用fig.show()内联一个IPython Notebook图形? [英] Plot an IPython Notebook figure inline with fig.show()?

查看:231
本文介绍了用fig.show()内联一个IPython Notebook图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm calling the inline mode for IPython Notebook using;

%pylab inline

以下代码会立即在单元格中绘制一个数字;

And the following code plots a figure immediately at the cell;

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

但是我想在一个单元格中创建绘图/轴等,稍后使用may绘图;

However I would like to create the plot/axes etc. in one cell, and plot later using maybe;

fig.show()

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

How do I gain more control of the inline mode? If I don't use %pylab inline, it creates the plot in a seperate window which I don't want (and it usually freezes the window).

版本;

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


推荐答案

所以我想你是什么想要的是:

So I guess what you want is this:

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))

要在另一个单元格中显示情节,只需使用:

To display the plot in another cell simply use:

fig

这篇关于用fig.show()内联一个IPython Notebook图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆