4

我有以下代码不起作用:

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)

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

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

上述代码的输出

4

1 回答 1

5

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

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

于 2013-09-30T15:36:20.533 回答