簡體   English   中英

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

[英]subplots_adjust in matplotlib does not work in 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)

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

我使用的是WinPython 3.3.2.3 64位,matplotlib版本1.3.0和CPython 3.3。 這發生在IPython Notebook中。 后端是直插式。 筆記本電腦的輸出已完成,但輸出文件未正確裁剪。 在notebook和saved文件中,subplots_adjust命令無效。

上面代碼的輸出

在tcaswell的幫助下,我通過完全關閉IPython Notebook並通過ipython-qtconsole重新運行代碼來解決問題。 似乎subplots_adjust()在ipython-notebook中對python 3不起作用。 我是python的新手,並且非常感興趣的是qtconsole和筆記本之間有什么區別,后端方面,如果有人有想法的話。

無論如何 - 很高興解決這個問題!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM