![](/img/trans.png)
[英]Dynamically update matplotlib figure in Jupyter notebook with Qt backend
[英]update matplotlib figure dynamically
我正在使用 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...")
應該只有兩個紅點並更新每個循環
我怎樣才能克服這個問題?
您upate的ydata
的smoothed_histogram
,你可以用你做同樣的事情*
標記:
import numpy as np
import matplotlib.pyplot as plt
n = 100
x = np.arange(n)
y = np.sort(np.random.random(n))
fig, ax = plt.subplots()
ax.plot(x, y)
h_marker = ax.plot(x[0], y[0], marker='o', color='r')[0]
for i in range(n):
h_marker.set_data(x[i], y[i])
plt.pause(0.01)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.