如何使用python matplotlib标记x轴

如何使用python matplotlib标记x轴,python,matplotlib,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 ('Relea

我正试图从我的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
如您所见,我使用第2列--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() 

您需要使用
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() 

不客气。如果您满意,请单击左侧的勾号接受答案。欢迎您。如果您满意,请单击左侧的勾号接受答案。