简体   繁体   中英

subplots_adjust in matplotlib does not work in IPython Notebook

I have the following code that did not work:

import matplotlib.pyplot as plt

# Make the plot
fig, axs = plt.subplots(3, 1, figsize=(3.27, 6))
axs[0].plot(range(5), range(5), label='label 1')
axs[0].plot(range(5), range(4, -1, -1), label='label 2')
axs[0].legend(bbox_to_anchor=(0, 1.1, 1., 0.1), mode='expand', ncol=2, frameon=True, borderaxespad=0.)

# Adjust subplots to make room
fig.subplots_adjust(top=.5)

fig.savefig('test.png', format='png', dpi=300)

It can be seen that the fig.subplots_adjust did not work at all.

I am using WinPython 3.3.2.3 64 bit, with matplotlib version 1.3.0 and CPython 3.3. This happened in IPython Notebook. The backend is the in-line one. The output from the notebook is complete, but the output file is improperly cropped. In both notebook & saved file, the subplots_adjust command has no effect.

上面代码的输出

With the help of tcaswell, I got it solved by entirely closing the IPython Notebook and re-run the code via the ipython-qtconsole. It seems that the subplots_adjust() simply doesn't work for python 3 in ipython-notebook. I am new to python, and is really interested in what difference is there between the qtconsole and the notebook, backend-wise, if anyone has got ideas.

Anyways - good to have this problem solved!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM