2011-04-09 35 views
2

當使用matplotlib時,我如何將文本設置爲低於其他對象,如矩形,LineCollections等?或者更一般地說,matplotlib如何決定對象在彼此重疊時出現的順序?與網格不同,沒有像使用Axes.set_textbelow()這樣的函數,我也使用了這個主題,但沒有得到滿意的結果。Matplotlib - 如何在其他對象重疊時設置文本?

下面是我用matplotlib繪製的股票圖表。請注意音量部分,我想將音符(白色文本)設置爲低於它們重疊的音量條。筆記是用Axes.text()繪製的Text對象,音量欄是使用Axes.vlines()繪製的LineCollection對象。

stock chart I draw with matplotlib

回答

3

您可能正在尋找ZORDER:

from pylab import * 

fig = figure(1) 
fig.clf() 
ax = subplot(111) 
rect = matplotlib.patches.Rectangle((0.2,0.2), 0.3, 0.3, fc = '0.5', ec = '0.0') 
ax.add_patch(rect) 
ax.text(.4, .4, "Help me, there is a rectangle stuck under me!") 

fig = figure(2) 
fig.clf() 
ax = subplot(111) 
rect = matplotlib.patches.Rectangle((0.2,0.2), 0.3, 0.3, fc = '0.5', ec = '0.0') 
ax.add_patch(rect) 
ax.text(.4, .4, "Help me, I'm stuck under a rectangle!", zorder = -1) 

show() 
+0

它的簡單和清晰。我已經嘗試過了,結果看起來和我期待的一樣好,謝謝@Daan! – 2011-04-09 16:50:41

相關問題