Geographic Information Systems Asked by Eddie E Massey III on May 4, 2021
I’m completely new to shapefiles. I was able to use GeoPandas to plot some data over a map of the US I got from census.gov. I’m having getting the map to be at a viewable size. I adjusted the figsize parameter multiple times, but it doesn’t seem to increase the size enough. From what I’ve read so far, shapefiles shouldn’t be modified. How can I make the subplot larger?
map_df = gdp.read_file(shape_file)
map_df.head()
map_df.plot()
covid_max_cap_df = hospital_data.groupby(['statename']).InBedsOccCOVID__Numbeds_Est.max()
covid_max_cap_df.drop('United States')
merged_map = map_df.set_index('NAME').join(covid_max_cap_df)
merged_map.rename(columns={'InBedsOccCOVID__Numbeds_Est':'covid_occ_rate'}, inplace=True)
var = 'covid_occ_rate'
vmin, vmax = covid_max_cap_df.min()-10, covid_max_cap_df.max()+10
fig, ax = plt.subplots(1,figsize=(30,30))
merged_map.plot(column=var, cmap='Reds', linewidth=0.8, ax=ax, edgecolor='0.8')
ax.axis('off')
ax.set_title('COVID-19 Peak Hospital Occupancy Rate', fontdict={'fontsize':25, 'fontweight':3})
ax.annotate('Source: CDC, June 2020',xy=(0.1, .08), xycoords='figure fraction',
horizontalalignment='left', verticalalignment='top',
fontsize=12, color='#555555')
sm = plt.cm.ScalarMappable(cmap='Reds',
norm=plt.Normalize(vmin=vmin, vmax=vmax))
sm._A = []
cbar = fig.colorbar(sm)
As stated in geopandas documentation, you can use mpl_toolkits
in order to fit and align the plot axes and the legend axes:
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig, ax = plt.subplots(1, 1)
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.1)
adm_gdf.plot(column='pop_est', ax=ax, legend=True, cax=cax)
There are other interesting alternatives in this other question.
Answered by ramiroaznar on May 4, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP