在地图上可视化饼图

时间:2019-06-04 00:59:51

标签: python data-visualization geo folium vincent

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

到目前为止我尝试过的:

  1. Google Data Studio:唯一的缺点是我们无法缩放地图,并且地图在国家/地区级别缩放,但是我所有的数据都是关于城市中的某个地区的。
  2. 带有Folium的Python:Folium是Leaflet.js的包装,非常适合地理可视化。但是,它缺少饼图功能。 I looked at integrating with Vega,但这仅对标记上的弹出窗口有用。这不好,我想直接在地图上显示饼图。

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

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

1 个答案:

答案 0 :(得分: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
}]

}