2016-03-04 130 views
1

我正在使用matplotlib來繪製5套約。每個400,000個數據點。雖然每組點都以不同的顏色繪製,但我需要不同的標記讓人們在黑白打印輸出時閱讀圖形。我面臨的問題是,http://matplotlib.org/api/markers_api.html文檔中幾乎所有可用的標記都需要花費太多時間來繪製和顯示。我只能找到兩個快速繪製和渲染的標記,這些是' - '和' - '。這是我的代碼:Matplotlib標記繪製和渲染快

plt.plot(series1,'--',label='Label 1',lw=5) 
plt.plot(series2,'-',label='Label 2',lw=5) 
plt.plot(series3,'^',label='Label 3',lw=5) 
plt.plot(series4,'*',label='Label 4',lw=5) 
plt.plot(series5,'_',label='Label 5',lw=5) 

我試過了多個標記。系列1和系列2迅速繪製並立即渲染。但系列3,4和5需要永久繪製和AGES顯示。

我無法弄清楚背後的原因。有人知道更多的繪圖和渲染的標記嗎?

+1

以及'「-''和'」 - 」 '會畫出線條,而不是標記,所以這可能是不同之處 – tom

回答

2

前兩個('--''-')是線條而不是標記。這就是爲什麼他們呈現得更快。

繪製〜400,000個標記是沒有意義的。你無法看到所有這些點......但是,你可以做的只是繪製點的一個子集。 因此,將所有數據添加到行中(即使您也可以對其進行二次抽樣),然後僅添加標記的第二行「行」。 的,你需要一個「X」的載體,它可以進行二次採樣太:

# define the number of markers you want 
nrmarkers = 100 

# define a x-vector 
x = np.arange(len(series3)) 
# calculate the subsampling step size 
subsample = int(len(series3)/nrmarkers) 
# plot the line 
plt.plot(x, series3, color='g', label='Label 3', lw=5) 
# plot the markers (using every `subsample`-th data point) 
plt.plot(x[::subsample], series3[::subsample], color='g', 
     lw=5, linestyle='', marker='*') 

# similar procedure for series4 and series5 

注:該代碼是從頭開始編寫,並沒有測試