【发布时间】:2020-12-28 19:05:22
【问题描述】:
我正在使用 matplotlib 绘制一些图形并动态更新它们
为此,我使用列出的代码中所示的 set_data 方法
问题:
当我需要为每一帧突出显示绘图上的某个点时,旧点仍在绘图上
#display pics
fig,ax = plt.subplots(2,4)
im3 = ax[0][3].plot(x,y)[0]
#################################################
# some image processing code #
#################################################
plt.ion()
for pic_index in range(no_of_pics):
im3.set_ydata(smoothed_histogram)
#im3.set_data(threshold,smoothed_histogram[threshold],'g*')
ax[0][3].plot(threshold,smoothed_histogram[threshold],'r*')
ax[0][3].plot(effective_threshold,smoothed_histogram[effective_threshold],'r*')
plt.pause(0.01)
input("Press any key to continue...")
应该只有两个红点,每个循环都更新
我该如何克服这个问题?
【问题讨论】:
-
尝试添加一个
plt.cla()来清除当前轴 -
我是这样做的 ax[0][3].cla() ax[0][3].plot(range(0,256),smoothed_histogram)[0] ax[0][3 ].plot(threshold,smoothed_histogram[threshold],'r*') ax[0][3].plot(effective_threshold,smoothed_histogram[effective_threshold],'r*')
标签: python matplotlib