您可以使用scatter
對點進行着色,並且假設您不打算繪製太多點數,只需每次使用不同顏色添加新點就可以了。基於衰變的小例子,
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def data_gen(t=0):
cnt = 0
while cnt < 1000:
cnt += 1
t += 0.01
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
def get_colour(t):
cmap = matplotlib.cm.get_cmap('Spectral')
return cmap(t%1.)
def init():
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(0, 10)
fig, ax = plt.subplots()
ax.grid()
def run(data):
# Get some data and plot
t, y = data
ax.scatter(t, y, c=get_colour(t))
#Update axis
xmin, xmax = ax.get_xlim()
if t >= xmax:
ax.set_xlim(xmin, 2*xmax)
ax.figure.canvas.draw()
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
repeat=False, init_func=init)
plt.show()
好辦法的確,這樣你的確可以繪製每DTP你想要的方式,在我的情況下,過多的數據點可能雖然是這樣,每個timeserie包含aprox的200萬個DTPS – LetsPlayYahtzee
問題是,使用'line.set_xaxis',你更新數據並可以使用'blit'來重繪新點(參見http://stackoverflow.com/questions/8955869/why-is-plotting-with-matplotlib-so -慢)。每次調用scatter都會將點添加爲新集合(不要以爲您可以追加到集合中)。爲了提高效率,您可以將少數2,000,000個點作爲一些集合來繪製,例如通過改變'data_gen'來一次返回/繪製塊(或者只有當你有足夠的點時繪圖,而不是'c'參數可以是一個值的數組)。 –
分散的另一個問題是,隨着動畫的進展以及越來越多的點被添加,密度增加了,除非放大,否則不能區分dtps的顏色,但在動畫中仍然很難放大 – LetsPlayYahtzee