我正在尝试从我的 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()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句