gpt4 book ai didi

python-2.7 - 用fig.show()内联绘制一个IPython Notebook图形?

转载 作者:行者123 更新时间:2023-12-04 17:23:40 25 4
gpt4 key购买 nike

我正在使用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

最佳答案

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

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来避免这种情况。

关于python-2.7 - 用fig.show()内联绘制一个IPython Notebook图形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15480379/

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