[英]Looping to plot multiple map with geopandas and removing axis
I would like to create a png that combines a similar chloropeth map of the UK at different subperiod.我想创建一个 png,它在不同的子时期结合了英国的类似 chloropeth map。 My input dataframe (df) has the following struture:我的输入 dataframe (df) 具有以下结构:
decade十年 | nb_patentees nb_专利权人 | area区域 |
---|---|---|
1910 1910 | 25 25 | zone1区域 1 |
1910 1910 | 15 15 | zone2区域 2 |
1920 1920 | 34 34 | zone1区域 1 |
1920 1920 | 35 35 | zone2区域 2 |
Here is what I do:这是我所做的:
fig, axes = plt.subplots(ncols=4, nrows=(len(list_decade)//4+1), figsize=(10,15))
i = 0
for dec in sorted(list_decade): #list_decade is a lost of decades [1900, 1910, 1920...]
j = i%4 # column
ax = axes[i//4, j]
ax.title.set_text(f"{dec}'s")
ax.axis("off")
df_dec = df.query("decade == @dec") # df is a dataframe containing all data, I keep only the relevant decade
df_dec.plot(column='nb_patentees', legend=True, edgecolor="black", figsize = (10,15), linewidth = 0.01, legend_kwds={'label': "Number of patentess (log)",
'orientation': "horizontal", 'shrink': 0.8}, ax = ax)
i = i+1
It works ok except when the number of subfigures does not match the square of cols x rows in which case I got an empty map with axes.它工作正常,除非子图的数量与 cols x 行的平方不匹配,在这种情况下,我得到一个带轴的空 map。 Do you know how can I get rid of it?你知道我怎样才能摆脱它吗?
This should remove the axis on your blank subplot:这应该删除空白子图上的轴:
axes[-1, -2].axis('off')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.