Created
October 15, 2022 00:01
-
-
Save rohithteja/3f0f9b5534b5795d6c1c820c971822d8 to your computer and use it in GitHub Desktop.
Choropleth city
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextily as cx | |
# read data | |
df = gpd.read_file('data/arrondissements/arrondissements.shp',encoding='utf-8') | |
df = df.to_crs(epsg=3857) | |
fig, ax = plt.subplots(1, figsize=(10, 6),dpi=300,facecolor='w',edgecolor='w') | |
# colorbar | |
divider = make_axes_locatable(ax) | |
cax = divider.append_axes('right', size='5%', pad=0.3) | |
#plot | |
gax = df.plot(ax=ax,cax=cax, column='perimetre', cmap='Reds', legend=True, edgecolor='black', linewidth=0.5,legend_kwds={'shrink':0.6},alpha=0.5) | |
# plot background map | |
cx.add_basemap(ax) | |
# add text | |
df.apply(lambda x: gax.annotate(x['l_aroff'], xy=x.geometry.centroid.coords[0], ha='center',size=6), axis=1) | |
ax.set_axis_off() | |
# label the colorbar | |
cax.tick_params(labelsize=10) | |
cax.set_ylabel('Perimeter',fontsize=10) | |
cax.yaxis.set_label_position('left') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment