I have a figure that contains two subplots in two rows and one column like so:
fig, (ax1, ax2) = subplots(
nrows=2,
ncols=1,
)
The two subplots are pie charts, therefore I want their axes to be square. After browsing the API, the following should be the correct way to adjust the axes of each subplot:
ax1.axis([0, 8, 0, 8])
ax2.axis([0, 8, 0, 8])
Then I adjust the size of the entire figure. Since the width of each subplot is 8 inches, I set the width of the figure to 8 inches as well and the height of the figure to 2*8=16 inches:
fig.set_size_inches(8, 16)
These settings result in nicely formatted pie charts. However, a label for one of the wedges of a pie is cut off at the right edge of the figure when I save the figure to a PDF file. The figure is more narrow in the saved file than in the preview window. That's why I want to widen the figure along the x axis but by retaining the axes of the subplots. If I just try to widen the figure by doing:
fig.set_size_inches(12, 16)
The figure gets wider now but, unfortunately, the two pie charts as well. From my understanding, the axis()
calls should retain the dimensions of the subplots but they don't. After reading and trying out a lot about autoscale, xlim, ylim etc., I'm even more confused and nothing works.
I simply want to widen the figure by retaining the dimensions of the subplots so that there is more whitespace along the x axis and the labels can be displayed without cutting them off. How do I do that?