1

I'm trying to create multiple subplots in one figure. The subplots are a shapefile polygon maps.

My shapefile has 4 different attributes ['s1', 's2', 's3', 's4'] that I’d like to show each on a separate map but want them all in one figure. so, I’ve done this:

import geopandas as gpd
import matplotlib.pyplot as plt

#Read shapefile
shpDF = gpd.read_file('myPath/myShapefile.shp')

#create plots
shpDF.plot()
fig, ax = plt.subplots(2, 2)#, figsize=(20, 12))#, figsize=(20, 12))
shpDF.plot(column='s1', ax=ax[0, 0], legend=True)
ax[0, 0].set_title('s1')
shpDF.plot(column='s2', ax=ax[0, 1], legend=True)
ax[0, 1].set_title('s2')
shpDF.plot(column='s3', ax=ax[1, 0], legend=True)
ax[1, 0].set_title('s3')
shpDF.plot(column='s4', ax=ax[1, 1], legend=True)
ax[1, 1].set_title('s4')
#set axis to 'off'
ax[0, 0].axis('off')
ax[0, 1].axis('off')
ax[1, 0].axis('off')
ax[1, 1].axis('off')
#tight layout
fig.tight_layout()

Which produces the below:

enter image description here

What I want instead is one Bar/Legend in the figure for all 4 subplots/maps. i.e. the colour scheme in all 4 maps will follow the one major bar/legend. I've tried removing the legend=True from 3 of them but this only means the small individual legend for the 4th is left.

martineau
  • 119,623
  • 25
  • 170
  • 301
mIT
  • 48
  • 6
  • 1
    You can check out this article from matplotlib on placing colorbars (https://matplotlib.org/stable/gallery/subplots_axes_and_figures/colorbar_placement.html). – nikost Feb 05 '22 at 00:47

0 Answers0