有什么方法可以绘制印度地图吗?
问题描述
我正在尝试使用 plotly 绘制印度地图,但无法找到方法.以下是我为美国尝试的代码.
输出:
以类似的方式,我只想绘制带有悬停值的印度地图.只想要下面的输出......印度地图的输出:
您使用的图形工厂 create_choropleth
方法是
为了更精细地控制绘图,我们可以直接使用图形对象:
I am trying to plot India map using plotly, but unable to find a way to do that. Below is the code which I tried for USA.
OUTPUT:
In a similar way I just want to draw India's map with hovering values. and just want output like below... the output of INDIAN MAP:
The figure factory create_choropleth
method that you're using is deprecated and deals with USA counties exclusively. For other maps, you need the GeoJSON for the features you're mapping. Plotly only comes with GeoJSON data for world countries and US states, so you'll have to provide the data for India's states yourself.
Like your example choropleth, let's plot the current number of active COVID-19 cases per state as of July 17 (this comes from indiacovid19.github.io, which is periodically archiving the data from India's Ministry of Health). As for the GeoJSON, a quick search yields a few GitHub repos but it seems the majority are too outdated for our cases data, as they don't include the merging of Dadra and Nagar Haveli and Daman and Diu. Luckily, datameet provides an up-to-date shapefile for India's states which I simplified a bit to reduce the size and converted to GeoJSON using mapshaper, then flipped the polygon winding using geojson-rewind.
Now, as detailed in the Plotly documentation, we can use plotly express to quickly make a choropleth map with our data:
For more fine control over the plot, we can use the graph objects directly:
这篇关于有什么方法可以绘制印度地图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!