2024-06-06 05:14:50 发布
网友
在我笔记本的一个单元格里,我已经用
myplot = plt.figure() plt.plot(x,y)
现在,在另一个单元格中,我想再次绘制完全相同的图形,但在其上添加新的绘图(类似于连续两次调用plt.plot())所发生的情况。我尝试在新单元中添加以下内容:
plt.plot()
myplot plt.plot(xnew,ynew)
然而,我在新牢房里得到的只有新的情节,没有了前一个。在
怎样才能做到这一点?在
基本上有两种方法可以解决这个问题。在
使用面向对象的方法,即保持图形和/或轴的句柄,并在以后的单元中重用它们。在
import matplotlib.pyplot as plt %matplotlib inline fig, ax=plt.subplots() ax.plot([1,2,3])
在后来的牢房里
建议阅读:
How to keep the current figure when using ipython notebook with %matplotlib inline?
How to add plot commands to a figure in more than one cell, but display it only in the end?
How do I show the same matplotlib figure several times in a single IPython notebook?
另一个选项是告诉matplotlib内联后端在单元格末尾保持图形打开。在
import matplotlib.pyplot as plt %matplotlib inline %config InlineBackend.close_figures=False # keep figures open in pyplot plt.plot([1,2,3])
然后在后面的牢房里
plt.plot([4,5,6])
'%matplotlib inline' causes error in following code
Manipulate inline figure in IPython notebook
基本上有两种方法可以解决这个问题。在
A、 面向对象方法
使用面向对象的方法,即保持图形和/或轴的句柄,并在以后的单元中重用它们。在
在后来的牢房里
^{pr2}$建议阅读:
How to keep the current figure when using ipython notebook with %matplotlib inline?
How to add plot commands to a figure in more than one cell, but display it only in the end?
How do I show the same matplotlib figure several times in a single IPython notebook?
B、 保持图形在pyplot
另一个选项是告诉matplotlib内联后端在单元格末尾保持图形打开。在
然后在后面的牢房里
建议阅读:
'%matplotlib inline' causes error in following code
Manipulate inline figure in IPython notebook
相关问题 更多 >
编程相关推荐