将IPython Notebook图形与fig.show()内联?

问题描述 投票:6回答:3

我正在使用IPython Notebook调用内联模式;

%pylab inline

下面的代码立即在单元格上绘制一个图形;

fig = plt.figure()
axes = fig.add_axes([0, 0, 1, 1])

但是我想在一个单元格中创建图/轴等,然后使用也许以后图;

fig.show()

如何获得对串联模式的更多控制?如果我不使用内联%pylab,它会在一个我不想要的单独窗口中创建绘图(并且通常会冻结该窗口)。

版本;

Numpy: 1.7.0
Matplotlib: 1.2.1rc1
Python: 2.7.2 (default, Jun 24 2011, 12:22:14) [MSC v.1500 64 bit (AMD64)]
Pandas: 0.10.1
PyLab: 1.7.0
python-2.7 matplotlib ipython ipython-notebook
3个回答
5
投票

您可能正在寻找禁用自动关闭图形的方法:

InlineBackend options
---------------------
--InlineBackend.close_figures=<CBool>
    Default: True
Close all figures at the end of each cell.
When True, ensures that each cell starts with no active figures, but it also
means that one must keep track of references in order to edit or redraw
figures in subsequent cells. This mode is ideal for the notebook, where
residual plots from other cells might be surprising.
When False, one must call figure() to create new figures. This means that
gcf() and getfigs() can reference figures created in other cells, and the
active figure can continue to be edited with pylab/pyplot methods that
reference the current active figure. This mode facilitates iterative editing
of figures, and behaves most consistently with other matplotlib backends,
but figure barriers between cells must be explicit.

仍然,如果单元格的最后一行返回无花果对象,则IPython将显示该图,您可以通过以;结束它或将pass作为最后一行来避免这种情况。


5
投票

所以我想你想要的是这个:


0
投票

[使用新的

© www.soinside.com 2019 - 2024. All rights reserved.