[英]how to label x-axis using python matplotlib
我正在嘗試從csv數據文件制作圖形。 我的代碼如下:
for name in per_data.dtype.names[2:]:
plt.plot(per_data['RELEASE'],per_data[name],label=name)
plt.legend(loc='upper left',prop = {'size':7},bbox_to_anchor=(1,1))
plt.tight_layout(pad=5)
plt.xlabel ('Release')
plt.ylabel ('Time/Sec')
plt.title ('Ingest Performance Test')
plt.grid()
plt.show()
我的csv數據是:
DATE RELEASE 10GB 100GB 200GB 400GB 600GB 800GB 1000GB
5/5/16 2.67 0.36 4.18 8.54 18 27 38 46
5/5/16 2.68 0.5 4.24 9.24 18 27 37 46
5/6/16 2.69 0.32 4.3 9.18 19 29 37 46
5/6/16 2.7 0.35 4.3 9.3 19 28 37 46
5/6/16 2.71 0.3 4.18 8.18 16 24 33 41
如您所見,我正在使用第二列-RELEASE作為我的x軸標簽。 問題是:實際發行版號為:2.67、2.68、2.69、2.70、2.71但是,在圖中,程序添加了加點(2.65、2.75、2.85、2.95和2.705)。 如何設置它,以便x軸的標簽可以反映我的發行號?
您需要使用plt.xticks()
如圖所示這里 。 它控制要用於x軸的刻度和標簽。
在您的示例中,您將必須添加另一行,如下所示:
for name in per_data.dtype.names[2:]:
plt.plot(per_data['RELEASE'],per_data[name],label=name)
plt.legend(loc='upper left',prop = {'size':7},bbox_to_anchor=(1,1))
plt.tight_layout(pad=5)
plt.xlabel ('Release')
plt.xticks (per_data['RELEASE'])
plt.ylabel ('Time/Sec')
plt.title ('Ingest Performance Test')
plt.grid()
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.