0
votes

I want to create square subplots which are publication quality using Matplotlib. Currently, I have 2 subplots which are made in a figure of size 8,5 and the X limits for both plots are different.

I would want both the subplots to be of square size rather than the Y axis being taller. Any suggestions ? Alternatively, is there a way where I can explicitly control the ratio of width and height of a subplot in matplotlib?

Below is the sample image which I have right now.

Matplotlib Plot with 2 subplots

1

1 Answers

2
votes

You can explicitly control the figure size, and you can explicitly set the axes' positions within a figure, as a fraction of the figure size.

fig = plt.figure(figsize=(8,4))
ax1 = fig.add_axes([0.1, 0.1, 0.4, 0.8])
ax1.plot(...)
ax2 = fig.add_axes([0.5, 0.1, 0.4, 0.8])
ax2.plot(...)

In addition, you can supply aspect='equal' to functions that create axes (add_axes, add_subplot) to force the axes shape to match the axes scales (not relevant for your linear-log plot).