gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:03:25 26 4
gpt4 key购买 nike

我有以下代码不起作用:

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 中。后端是在线后端。 notebook 的输出是完整的,但输出文件裁剪不当。在笔记本和保存的文件中,subplots_adjust 命令无效。

The output of the above code

最佳答案

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

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

关于python - matplotlib 中的 subplots_adjust 在 IPython Notebook 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19058239/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com