假设我有一些数据,并且我想通过将其传递给自定义绘图函数 (myplot()) 来创建这些数据的绘图。我在 myplot() 中使用 matplotlib 的模块。
我希望 myplot() 将句柄返回到图形,而不是在调用此函数时显示图形。这是 iPython 的示例代码和输出。
我对此有两个问题:
- 为什么我仍然看到一个情节,即使我将 myplot() 的输出分配给 f?
- 当我将 myplot() 的输出分配给一个变量时,我需要什么来抑制这个图?
假设我有一些数据,并且我想通过将其传递给自定义绘图函数 (myplot()) 来创建这些数据的绘图。我在 myplot() 中使用 matplotlib 的模块。
我希望 myplot() 将句柄返回到图形,而不是在调用此函数时显示图形。这是 iPython 的示例代码和输出。
我对此有两个问题:
启动ipython
ipython notebook
而不是
ipython notebook --pylab=inline
如果您不想以非内联方式启动整个笔记本,您可以使用以下代码:
%config InlineBackend.close_figures = False
def myplot(t,x):
fig = figure()
x = plot(t,x)
fig.savefig('plot.png') # This is just to show the figure is still generated
return fig
t = arange(0,6,0.01)
x = sin(t)
f = myplot(t,x)