简体   繁体   English

地理图,即来自荷兰

[英]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 .好吧,我遇到了同样的问题,所以这就是我如何使用matplotlibpandasgeopandas解决类似问题的方法。 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

1. Loading the map 1.加载地图

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)

It looks like this:它看起来像这样: 在此处输入图像描述

2. Filling with data 2. 填写数据

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中。

3. Final Result 3. 最终结果

Now I can plot my data:现在我可以绘制我的数据:

mapdf.plot(column="BUY", figsize=(10,10), legend=True)

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从matplotlib底图图中以交互方式获取可读(即lng / lat)坐标? - Interactively get readable(i.e. lng/lat) coordinates from a matplotlib basemap plot? 如何在极坐标 matplotlib plot 上使用 plot 带有文本(即标签)的水平线? (Python) - How to plot horizontal lines with text (i.e. a label) on a polar coordinates matplotlib plot? (Python) python作为“批处理”脚本(即从python运行命令) - python as a “batch” script (i.e. run commands from python) 使用BeautifulSoup从HTML中提取外国字符(即中文)? - foreign characters (i.e. Chinese) from HTML using BeautifulSoup? 如何从输出(即[])和其他删除括号 - How to remove brackets from output (i.e. [ ]) and other 为存在的元素绘制两个向量-即跳过没有条目的行 - Plot two vectors for elements which exist - i.e. skip rows without entries 如何在 matplotlib.pyplot.quiver plot 中获取箭头方向(即 U 和 V)? - How to get arrow directions (i.e. U and V) in a matplotlib.pyplot.quiver plot? 为 output_server() 指定 doc-id 和 plot-id(即 URL) - Specifying doc-id and plot-id (i.e. the URL) for output_server() 为什么每个绘图命令(即标签、标题)在 spyder 中开始一个新的绘图而不是出现在一个图形上? - why does each plot command (i.e. labels,title) start a new plot in spyder instead of appearing on one graph? 我可以从共享文件中导入模块列表吗? 即我可以进口进口吗? - Can I import a list of modules from a shared file? i.e. can I import imports?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM