[英]Symbol colour in legend in errorbar plot does not correspond to colour on figure
在下面的示例中,data_3的圖例中的顏色將與plt.errorbar([..],color ='red')中設置的顏色不同。 扼殺僅適用於某些符號和顏色組合。 例如,紅色方塊將在圖例中顯示為黑色方塊,但是紅色圓圈將正確顯示在圖例中。 當圖例位於圖的外部時,這似乎只是一個問題。 這是一個工作示例:將matplotlib.pyplot導入為plt導入matplotlib將seaborn導入為sns sns.set()#將繪圖樣式設置為seaborn
matplotlib.rcParams['legend.handlelength'] = 0
matplotlib.rcParams['legend.markerscale'] = 1
labels = ['data_1','data_2','data_3','data_4']
symbols = ['o','D','s','D']
fill_style = ['none','full','none','full']
colours = ['MediumPurple','Maroon','red','yellowGreen']
x=range(10)
y=range(10)
for i in range(len(symbols)):
plt.errorbar(x,[a+i*2 for a in y],elinewidth=1,color=colours[i],fmt=symbols[i],label=labels[i],ms=4,fillstyle=fill_style[i],markeredgewidth=1.75,markeredgecolor=colours[i])
plt.legend(loc='center left',bbox_to_anchor=(1, 0.5))
剛意識到這只是在jupyter筆記本中顯示圖形時的問題。 當您將圖形另存為.pdf或.png時,圖例條目都會按應有的方式顯示,如您從我提供的圖形中所見!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.