2013-09-27 123 views
3

我有下面的代码没有工作:subplots_adjust在matplotlib不IPython的笔记本电脑工作

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命令不起作用。

The output of the above code

+0

这是你在笔记本中看到的,或者它保存的东西吗? – tacaswell

+0

@tcaswell这是它节省的。我在笔记本上看到的是非常正常的 - 我可以看到整个情节,但仍然subplots_adjust根本不起作用。感谢您提出一个好问题! –

+0

这是否在线? 'matplotlib.get_backend()'返回什么? – tacaswell

回答

3

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

反正 - 很好解决这个问题!

相关问题