简体   繁体   English

在pylab中重新初始化图

[英]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_xdataset_ydata更新数据, set_xdata数据是在创建新绘图(使用pylab.plotpylab.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.

相关问题 在Tensorflow中重新初始化变量 - Re-initialize variables in Tensorflow python中的multiprocess是否重新初始化全局变量? - Does multiprocess in python re-initialize globals? 将TensorFlow中的变量重新初始化为自定义值 - Re-initialize variable in TensorFlow to custom value 如何不在 Tensorflow 中重新初始化预训练的加载模型? - How to not re-initialize the pretrained loaded model in Tensorflow? 如何在Django SessionWizardView中重新初始化会话变量 - How to re-initialize a session variable in a Django SessionWizardView 如何重新初始化python pyqt5 gui - How do I re-initialize a python pyqt5 gui tensorflow 在 for 循环中训练时是否重新初始化权重? - Does tensorflow re-initialize weights when training in a for loop? PyGame 在重新连接时重新初始化 USB MIDI 设备 - PyGame Re-Initialize USB MIDI Device on Reconnect 在 Python 中重置(重新初始化)整数列表(为 0)的最佳方法是什么 - What is the best way to reset (re-initialize) a list of integers (to 0) in Python GUnicorn + CUDA:无法在分叉子进程中重新初始化 CUDA - GUnicorn + CUDA: Cannot re-initialize CUDA in forked subprocess
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM