maximusdooku
maximusdooku

Reputation: 5542

How can I reduce whitespace in Python plot?

I am plotting 2 shapefiles (converted to geopandas dataframe) using this. But there is too much whitespace. How can I reduce it to fill the box more with the map? The xlim and ylim doesn't seem to have any impact

f, ax = plt.subplots(1, figsize=(8, 8))
polydatx.plot(ax = ax, column = 'Elev_Avg', cmap='OrRd', scheme='quantiles')
segdatx.plot(ax = ax)
ax.grid(False)
ax.set_ylim(47, 47.3)
plt.axis('equal');

enter image description here

Upvotes: 1

Views: 350

Answers (1)

CodeZero
CodeZero

Reputation: 1699

The problem lies in calling

plt.axis('equal')

after setting the new ylim.

From the docs:

axis('equal') changes limits of x or y axis so that equal increments of x and y have the same length; a circle is circular.:

axis('scaled') achieves the same result by changing the dimensions of the plot box instead of the axis data limits.

In your case I would adjust the figure size to some rectangle, not a square and use axis('scaled').

Upvotes: 2

Related Questions