matplotlib 中的 subplots_adjust 在 IPython Notebook 中不起作用

Yux*_*ang 4 python matplotlib ipython-notebook

我有以下代码不起作用:

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)
Run Code Online (Sandbox Code Playgroud)

可以看出 fig.subplots_adjust 根本不起作用。

我使用的是 WinPython 3.3.2.3 64 位,matplotlib 版本 1.3.0 和 CPython 3.3。这发生在 IPython Notebook 中。后端是内联的。笔记本的输出是完整的,但是输出文件裁剪不当。在 notebook 和保存的文件中, subplots_adjust 命令无效。

上面代码的输出

Yux*_*ang 5

在 tcaswell 的帮助下,我通过完全关闭 IPython Notebook 并通过 ipython-qtconsole 重新运行代码解决了这个问题。似乎 subplots_adjust() 根本不适用于 ipython-notebook 中的 python 3。我是 python 的新手,如果有人有想法的话,我对 qtconsole 和笔记本之间的区别非常感兴趣,后端明智。

无论如何 - 很高兴解决这个问题!