[英]Re-initialize the plot in pylab
I am new to using PyLab. 我是使用PyLab的新手。 I want to plot some points. 我想画点。 But I don't want to show the previous points ie as a new point comes the previous plotted point will vanish and the new point will be plotted. 但是我不想显示先前的点,即随着新点的出现,先前绘制的点将消失而新点将被绘制。 I have searched a lot but I could not find how to re-initialize the plot in between. 我进行了很多搜索,但找不到如何重新初始化之间的绘图。 The problem I am facing is I can set the current figure by using plt.figure(f1.number) but after plotting the point in that figure it gets permanently changed. 我面临的问题是我可以使用plt.figure(f1.number)设置当前图形,但是在该图形中绘制点之后,它将永久更改。
plt.hold(False)
before you start plotting will do what you want. 开始绘制之前, plt.hold(False)
会完成您想要的操作。
hold
determines of old artists are held-on to when new ones are plotted. hold
确定旧艺术家在绘制新艺术家时的坚持。 The default is for hold to be on. 默认设置为保持。
ex 前
# two lines
plt.figure()
plt.hold(True)
plt.plot(range(5))
plt.plot(range(5)[::-1])
#one line
plt.figure()
plt.hold(False)
plt.plot(range(5))
plt.plot(range(5)[::-1])
Changing it via plt.hold
changes it for all (new) axes. 通过plt.hold
更改它plt.hold
更改所有(新)轴。 You can change the hold state for an individual axes
by 您可以通过以下方式更改单个axes
的保持状态:
ax = gca()
ax.hold(True)
With pylab, pylab.clf()
should clear the figure, after which you can redraw the plot. 使用pylab时, pylab.clf()
应该清除该图,然后可以重绘该图。
Alternatively, you can update your data with set_xdata
and set_ydata
that are methods on the axes object that gets returned when you create a new plot (either with pylab.plot
or pylab.subplot
). 另外,您可以使用set_xdata
和set_ydata
更新数据, set_xdata
数据是在创建新绘图(使用pylab.plot
或pylab.subplot
)时返回的set_ydata
对象上的方法。
The latter is probably preferred, but requires a litte more work. 后者可能是首选,但需要更多工作。 One example I can quickly find is another SO question . 我可以很快找到的一个例子是另一个SO问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.