python 如何为所有的区域分布图设置相同的比例尺范围?

shyt4zoc  于 2023-01-04  发布在  Python
关注(0)|答案(1)|浏览(157)

因此,我决定挑战自己,绘制2020年到2022年巴西各州新增日冕病例的区域分布图。我遇到的问题是,这些Map并非都有相同的比例尺或比例尺上的相同范围,因此可能会导致误解。右侧出现的图例或色带是第一张Map的图例,而且所有的Map都不一样,我怎么能让所有的Map都有相同的比例尺,从0到4. 5?

  • 这是我的密码 *
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

states_info = gpd.read_file(r'C:\Users\lepae\Documents\IGTI\Programação\Udemy - Python for Data Science and Machine Learning Bootcamp\Py_DS_ML_Bootcamp-master\Refactored_Py_DS_ML_Bootcamp-master\09-Geographical-Plotting\bcim_2016_21_11_2018.gpkg', layer = 'lim_unidade_federacao_a')

corona_cases = pd.read_csv('HIST_PAINEL_COVIDBR_2022_Parte1_14abr2022.csv',  sep=';')

merged_df = pd.merge(left=states_info, right=corona_sum, left_on='sigla', right_on='estado')
#(repeats same process for all the semesters)
#...

fig, axs = plt.subplots(2,3, figsize=(16,10), 
                        constrained_layout=True, 
                        sharex=True, sharey=True, 
                        subplot_kw=dict(aspect='equal'))

merged_df_2020_01.plot(column='casosNovos', ax=axs[0,0], figsize = (16,10), cmap = 'Reds', edgecolor= 'black')
axs[0,0].set_title('First semester of 2020')

merged_df_2020_02.plot(column='casosNovos', ax=axs[0,1], figsize = (16,10), cmap = 'Reds', edgecolor= 'black')
axs[0,1].set_title('Second semester of 2020')

merged_df_2021_01.plot(column='casosNovos', ax=axs[0,2], figsize = (16,10), cmap = 'Reds', edgecolor= 'black')
axs[0,2].set_title('First semester of 2021')

merged_df_2021_02.plot(column='casosNovos', ax=axs[1,0], figsize = (16,10), cmap = 'Reds', edgecolor= 'black')
axs[1,0].set_title('Second semester of 2021')

merged_df.plot(column='casosNovos', ax=axs[1,1], figsize = (16,10), cmap = 'Reds', edgecolor= 'black')
axs[1,1].set_title('First semester of 2022')

fig.delaxes(axs[1,2])
fig.suptitle('Number of new cases of COVID-19 per Brazilian States', fontsize=20, y=1.05)
patch_col = axs[0,0].collections[0]
cb = fig.colorbar(patch_col, ax=axs, shrink = 0.95)

我目前拥有的图片:[1]:https://i.stack.imgur.com/P9bKy.png

fdbelqdn

fdbelqdn1#

我遇到了同样的问题,我找到了这个链接,它帮助我修复了这个问题。基本上,它说输入一个vmax值,这样范围就被强制增加到一个特定的值。https://gis.stackexchange.com/questions/439233/use-geopandas-to-force-a-choropleth-to-use-a-legend-with-a-greater-range-than-th/439363
在您的情况下,由于您希望将范围设置为4.5,因此可以将vmax设置为4.5

cb = fig.colorbar(patch_col, ax=axs, shrink = 0.95, vmax = 4.5)

相关问题