我试着从一个数据框中画出一行-
print(df)
Agent ID Tenure in Month As of 2014 City State P201101 \
0 1000000 65 Jersey City New Jersey 881.940392
P201102 P201103 P201104 P201105 P201106 ... \
0 166.368261 1261.927008 531.211925 750.33716 357.73649 ...
P201306 P201307 P201308 P201309 P201310 P201311 \
0 1041.047706 639.671717 392.27343 860.148349 427.732344 972.562812
P201312
0 593.675603 我已经将代理Id为1000000的记录从数据帧分割出来,现在我想使用matplotlib绘制月度销售数据(从P201101到P201312)。
下面是我的代码-
x = list(df.columns[4:40])
y= df.iloc[:,4:40].values.tolist()
plt.plot(y[0])
plt.show()不幸的是,x轴显示的值为0,5,10.....I希望x轴显示P201101、P201102、.....、P201312。我也尝试过使用xlabel,xticks,但这并不能解决问题。请帮帮忙

发布于 2016-04-29 00:13:55
问题是我应该单独指定x轴。更正后的代码如下所示-
x=list(range(1,37))
xticks = list(df.columns[4:40])
y= df.iloc[:,4:40].values.tolist()
print(x,y[0])
plt.plot(y[0])
plt.title("Agent ID "+str(list(df['Agent ID'])))
plt.xticks(x,xticks,rotation = 90)
plt.show()https://stackoverflow.com/questions/36916817
复制相似问题