Ryan Nelson
2015-03-13 18:59:29 UTC
I'm constructing a multi-plot figure using an IPython notebook (v3) and
matplotlib (v1.4.3) inline magic. I was manually setting the axes bounds,
and I ended up with something like the following:
########
import matplotlib.pyplot as plt
%matplotlib inline
bottom = 0.12
top = 0.9
left = 0.12
axwidth = (1-(left*2))/3
fig = plt.figure(figsize=(10,4))
ax1 = fig.add_axes((left, bottom, axwidth, top))
ax1.set_title('Title')
#ax1.tick_params(labelleft=False)
ax2 = fig.add_axes((left+axwidth, bottom, axwidth, top),
sharex=ax1, sharey=ax1)
ax2.tick_params(labelleft=False)
ax3 = fig.add_axes((left+axwidth*2, bottom, axwidth, top),
sharex=ax1, sharey=ax1)
ax3.tick_params(labelleft=False)
fig.savefig('junk.pdf', format='pdf')
fig.savefig('junk2.png')
#######
Obviously, the bottom+top that I've selected is >1, so the axes should go
off the top of the figure. (Stupid, I know...) The axes in both the PDF and
PNG formatted files are clipped by the top of the figure as you would
expect; however, the figure that is displayed in the Notebook looks just
fine. In addition, if you add a title to one of the axes, the figure in
IPython suddenly creates more space for the text. Maybe it is rearranging
the axes information behind the scenes?
I'm curious why this design decision was made. I would say this is a bug.
Now that I know about this behavior, I can easily fix it. But new users
will be baffled when their saved figure looks nothing like the displayed
figure in the notebook.
Ryan
matplotlib (v1.4.3) inline magic. I was manually setting the axes bounds,
and I ended up with something like the following:
########
import matplotlib.pyplot as plt
%matplotlib inline
bottom = 0.12
top = 0.9
left = 0.12
axwidth = (1-(left*2))/3
fig = plt.figure(figsize=(10,4))
ax1 = fig.add_axes((left, bottom, axwidth, top))
ax1.set_title('Title')
#ax1.tick_params(labelleft=False)
ax2 = fig.add_axes((left+axwidth, bottom, axwidth, top),
sharex=ax1, sharey=ax1)
ax2.tick_params(labelleft=False)
ax3 = fig.add_axes((left+axwidth*2, bottom, axwidth, top),
sharex=ax1, sharey=ax1)
ax3.tick_params(labelleft=False)
fig.savefig('junk.pdf', format='pdf')
fig.savefig('junk2.png')
#######
Obviously, the bottom+top that I've selected is >1, so the axes should go
off the top of the figure. (Stupid, I know...) The axes in both the PDF and
PNG formatted files are clipped by the top of the figure as you would
expect; however, the figure that is displayed in the Notebook looks just
fine. In addition, if you add a title to one of the axes, the figure in
IPython suddenly creates more space for the text. Maybe it is rearranging
the axes information behind the scenes?
I'm curious why this design decision was made. I would say this is a bug.
Now that I know about this behavior, I can easily fix it. But new users
will be baffled when their saved figure looks nothing like the displayed
figure in the notebook.
Ryan