0

I am trying to plot side by side GeoPandas shapefiles using matplotlib but the titles, xlabel and ylabel are not plotting correctly.

fig, axes = plt.subplots(1,2, figsize=(10,3), sharex=True, sharey=True)

base = subs.boundary.plot(color='black', linewidth=0.1, ax=axes[0])
cluster.plot(ax=base, column='pixel', markersize=20, legend=True, zorder=2)
plt.title('THHZ')
plt.xlabel('Longitude')
plt.ylabel('Latitude')


base = forest.boundary.plot(color='black', linewidth=0.2, ax=axes[1])
cluster.plot(ax=base, column='forest', markersize=20, legend=True, zorder=2)
plt.title('Forest')

This is what I get

enter image description here

This is what I want

enter image description here

1 Answer 1

1

its because if you do plt.something matplotlib always takes the last axes! So instead of plt.set_xlabel do the following:

fig, (ax1, ax2) = plt.subplots(1,2, figsize=(10,3), sharex=True, sharey=True)
ax1.set_xlabel("asdf")
ax2.set_xlabel("asdf")
...

and for the geopandas plots pass the axis as gdf.plot(ax=ax1, ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.