Mar*_*nes 5 matplotlib ipython python-2.7 ipython-notebook
我正在调用IPython Notebook的内联模式;
%pylab inline
Run Code Online (Sandbox Code Playgroud)
以下代码立即在单元格中绘制一个数字;
fig = plt.figure()
axes = fig.add_axes([0, 0, 1, 1])
Run Code Online (Sandbox Code Playgroud)
但是我想在一个单元格中创建绘图/轴等,稍后使用也可以绘制;
fig.show()
Run Code Online (Sandbox Code Playgroud)
如何获得对内联模式的更多控制?如果我不使用%pylab inline,它会在一个我不想要的单独窗口中创建绘图(并且它通常会冻结窗口).
版本;
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
Run Code Online (Sandbox Code Playgroud)
你可能正在寻找禁用autoclose数字:
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.
Run Code Online (Sandbox Code Playgroud)
仍然,如果一个单元格的最后一行返回一个无花果对象,IPython将显示该数字,您可以通过以a结尾;或添加pass为最后一行来避免这种情况.
小智 5
所以我猜你想要的是这个:
from matplotlib.backends.backend_agg import FigureCanvasAgg as fc
fig = Figure()
canvas = fc(fig)
ax = fig.add_subplot(1, 1, 1)
ax.plot(arange(10))
Run Code Online (Sandbox Code Playgroud)
要在另一个单元格中显示绘图,只需使用:
fig
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8641 次 |
| 最近记录: |