【问题标题】:Visualizing pie charts on a map在地图上可视化饼图
【发布时间】:2019-10-19 12:39:53
【问题描述】:

我有一个 excel,其中每一行都有与一些整数值相关联的纬度和经度数据。我想将其可视化为地图上的饼图。

到目前为止我尝试了什么:

  1. Google 数据工作室:这里唯一的缺点是我们无法放大地图,而且地图是在国家一级放大的,但我所有的数据都是关于城市中的一个地区。
  2. Python with Folium:Folium 是 Leaflet.js 的包装器,非常适合地理可视化。但是它缺少饼图功能。 I looked at integrating with Vega 但这仅适用于标记上的弹出窗口。这个不好,我要直接地图上的饼图。

您能为此推荐任何免费工具或 Python 解决方案吗?

我主要来自 Python 背景,但我也欢迎基于 JS 的解决方案。

【问题讨论】:

    标签: python data-visualization geo folium vincent


    【解决方案1】:

    我认为Highcharts 可以帮助您找到所需的内容。它们基于 javascript。

    你正在寻找的一个例子 -

    https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/maps/demo/map-pies/

    {
    title: {
        text: 'USA 2016 Presidential Election Results'
    },
    
    chart: {
        animation: false // Disable animation, especially for zooming
    },
    
    colorAxis: {
        dataClasses: [{
            from: -1,
            to: 0,
            color: 'rgba(244,91,91,0.5)',
            name: 'Republican'
        }, {
            from: 0,
            to: 1,
            color: 'rgba(124,181,236,0.5)',
            name: 'Democrat'
        }, {
            from: 2,
            to: 3,
            name: 'Libertarian',
            color: libColor
        }, {
            from: 3,
            to: 4,
            name: 'Green',
            color: grnColor
        }]
    },
    
    mapNavigation: {
        enabled: true
    },
    // Limit zoom range
    yAxis: {
        minRange: 2300
    },
    
    tooltip: {
        useHTML: true
    },
    
    // Default options for the pies
    plotOptions: {
        mappie: {
            borderColor: 'rgba(255,255,255,0.4)',
            borderWidth: 1,
            tooltip: {
                headerFormat: ''
            }
        }
    },
    
    series: [{
        mapData: Highcharts.maps['countries/us/us-all'],
        data: data,
        name: 'States',
        borderColor: '#FFF',
        showInLegend: false,
        joinBy: ['name', 'id'],
        keys: ['id', 'demVotes', 'repVotes', 'libVotes', 'grnVotes',
            'sumVotes', 'value', 'pieOffset'],
        tooltip: {
            headerFormat: '',
            pointFormatter: function () {
                var hoverVotes = this.hoverVotes; // Used by pie only
                return '<b>' + this.id + ' votes</b><br/>' +
                    Highcharts.map([
                        ['Democrats', this.demVotes, demColor],
                        ['Republicans', this.repVotes, repColor],
                        ['Libertarians', this.libVotes, libColor],
                        ['Green', this.grnVotes, grnColor]
                    ].sort(function (a, b) {
                        return b[1] - a[1]; // Sort tooltip by most votes
                    }), function (line) {
                        return '<span style="color:' + line[2] +
                            // Colorized bullet
                            '">\u25CF</span> ' +
                            // Party and votes
                            (line[0] === hoverVotes ? '<b>' : '') +
                            line[0] + ': ' +
                            Highcharts.numberFormat(line[1], 0) +
                            (line[0] === hoverVotes ? '</b>' : '') +
                            '<br/>';
                    }).join('') +
                    '<hr/>Total: ' + Highcharts.numberFormat(this.sumVotes, 0);
            }
        }
    }, {
        name: 'Separators',
        type: 'mapline',
        data: Highcharts.geojson(Highcharts.maps['countries/us/us-all'], 'mapline'),
        color: '#707070',
        showInLegend: false,
        enableMouseTracking: false
    }, {
        name: 'Connectors',
        type: 'mapline',
        color: 'rgba(130, 130, 130, 0.5)',
        zIndex: 5,
        showInLegend: false,
        enableMouseTracking: false
    }]
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多