[英]geographical plot i.e. from Netherlands
I found this website to get geographical data per country: https://gadm.org/ .我发现这个网站可以获取每个国家/地区的地理数据: https ://gadm.org/。
Now I want to import the data from the Netherlands in python and plot my numerical data per province/city in that geographical map.现在我想用 python 从荷兰导入数据,并在该地理地图中绘制每个省/市的数字数据。
Someone who has experience with data from this site?有使用此站点数据经验的人吗? Or with other data for geographical plotting in certain countries?
或者与某些国家/地区的其他地理绘图数据一起使用?
I don't succeed loading this data into Python.我没有成功将这些数据加载到 Python 中。
Well I ran into the same issue so here is how I solved a similar problem using matplotlib
, pandas
and geopandas
.好吧,我遇到了同样的问题,所以这就是我如何使用
matplotlib
、 pandas
和geopandas
解决类似问题的方法。 Also some inspiration from this article: https://towardsdatascience.com/lets-make-a-map-using-geopandas-pandas-and-matplotlib-to-make-a-chloropleth-map-dddc31c1983d本文还有一些灵感: https ://towardsdatascience.com/lets-make-a-map-using-geopandas-pandas-and-matplotlib-to-make-a-chloropleth-map-dddc31c1983d
First I downloaded a shapefile of the dutch provinces (if you want other regions, eg communes, find a shapefile of those).首先,我下载了荷兰各省的 shapefile(如果您想要其他地区,例如公社,请找到这些的 shapefile)。 I used this one: https://maps.princeton.edu/catalog/stanford-st293bj4601 , the direct link to the download is: https://stacks.stanford.edu/file/druid:st293bj4601/data.zip
我用的是这个: https ://maps.princeton.edu/catalog/stanford-st293bj4601,直接下载链接是: https ://stacks.stanford.edu/file/druid:st293bj4601/data.zip
I opened it like this:我这样打开它:
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
mapdf = gpd.read_file("https://stacks.stanford.edu/file/druid:st293bj4601/data.zip")
This map contains provinces and bodies of water.这张地图包含省份和水域。 I only kept the provinces since I dont care about the bodies of water, and I also sorted the data on the province names
我只保留了省份,因为我不关心水体,并且我还对省份名称的数据进行了排序
mapdf = mapdf[mapdf["TYPE_1"] == "Provincie"]
mapdf.sort_values("NAME_1", inplace=True)
mapdf = mapdf.reset_index(drop=True)
So this is what my data sumdf
looks like:所以这就是我的数据
sumdf
样子:
I made sure the provinces are in the same order as in the mapdf
我确保各省的顺序与
mapdf
中的顺序相同
Now that they have the same length and are in the same order I can concatenate.现在它们具有相同的长度并且顺序相同,我可以连接。 If for some reason you cant easily get your data in the same order, then maybe look on joining it or using some other way to combine them correctly.
如果由于某种原因您无法轻松地以相同的顺序获取数据,那么也许可以考虑加入它或使用其他方式正确组合它们。
I combine them我把它们结合起来
mapdf = gpd.GeoDataFrame(pd.concat([sumdf, mapdf], axis=1))
and get并得到
You can see the column names, we now have both data in one dataframe
.您可以看到列名,我们现在将两个数据都放在一个
dataframe
中。
Now I can plot my data:现在我可以绘制我的数据:
mapdf.plot(column="BUY", figsize=(10,10), legend=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.