[英]Plotting values on map with geopandas
I have these data from the years 1991-2020 and for five countries.我有 1991-2020 年和五个国家的这些数据。
Date Temperature Units Year Month Statistics Country CODE
Jan 2020 -26.2 Celsius 1991 Jan Average Canada CAN
Feb 2020 -21.0 Celsius 1991 Feb Average Canada CAN
Mar 2020 -18.2 Celsius 1991 Mar Average Canada CAN
Apr 2020 -8.6 Celsius 1991 Apr Average Canada CAN
May 2020 0.8 Celsius 1991 May Average Canada CAN
m2020 m2020
pop_est continent name CODE ... Country ISO2 latitude longitude
0 35623680 North America Canada CAN ... Canada CA 56.130366 -106.346771
1 35623680 North America Canada CAN ... Canada CA 56.130366 -106.346771
2 35623680 North America Canada CAN ... Canada CA 56.130366 -106.346771
3 35623680 North America Canada CAN ... Canada CA 56.130366 -106.346771
4 35623680 North America Canada CAN ... Canada CA 56.130366 -106.346771
In the world map, I am plotting the temperature of each country for the year 2020. I want to create a plot for each month, so I created a loop that goes through each month.在世界 map 中,我正在绘制 2020 年每个国家/地区的温度。我想为每个月创建一个 plot,所以我创建了一个每个月都经过的循环。 When I plot, I do get 12 plots but the values of Temperature do not change throughout the months.当我 plot 时,我确实得到了 12 个图,但温度的值在几个月内都没有变化。 Do you know what can be the problem?你知道可能是什么问题吗? In my plot I want to see that for example in January Canada shows a blue color indicating -26, and for May it shows a green color indicating 0.8 degrees.在我的 plot 中,我想看到例如 1 月加拿大显示蓝色表示 -26,5 月显示绿色表示 0.8 度。
I did this:我这样做了:
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))world.columns=['pop_est', 'continent', 'name', 'CODE', 'gdp_md_est', 'geometry']
for i in m2020.groupby(['Month']).Month:
fig, ax = plt.subplots(figsize=(15,12))
world.plot(ax=ax, color='lightgrey')
m2020.plot(x="longitude", y="latitude", kind="scatter",
c='Temperature', colormap="hsv",
ax=ax)
plt.title(i[0])
plt.show()
You can try at first inserting the range of min and max temperature variables before the for-loop:您可以先尝试在 for 循环之前插入最小和最大温度变量的范围:
vmin=m2020["Temperature"].min() vmin=m2020["温度"].min()
vmax=m2020["Temperature"].max() vmax=m2020["温度"].max()
Then modify the third line inside the for-loop:然后修改for循环内的第三行:
m2020.plot("Temperature",x="longitude", y="latitude", kind="scatter",
vmin=vmin, vmax=vmax, colormap="hsv",ax=ax)
A similar exercise is made here:这里做了一个类似的练习:
https://towardsdatascience.com/how-to-use-python-to-obtain-the-temperature-of-any-place-on-earth-b92aae44b831 https://towardsdatascience.com/how-to-use-python-to-obtain-the-temperature-of-any-place-on-earth-b92aae44b831
When just copy-pasting the code, some errors were raised in my case.当只是复制粘贴代码时,在我的案例中出现了一些错误。 I needed to do a bit of debugging, but in the end you can get it working.我需要做一些调试,但最后你可以让它工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.