2015-04-17 113 views
0

我有一个15轴标签的情节和熊猫自动默认显示每隔一个类别的名称。如何在不跳过项目的情况下显示所有x轴标签?熊猫跳过x刻度标签

rows = [] 
for x in range(0,14): 
    rows.append(['a',14-x]) 

df = pd.DataFrame(rows) 
df = df.set_index(0) 
df.plot(xticks=df.index) 
+0

确定你能发布代表性数据然后 – EdChum

+0

当然,这个数据现在有相同的错误 – Chris

回答

4

您可以第一轴定义,使用关键字ax创建情节和设置刻度和刻度标记使用ax.set_xticks()http://matplotlib.org/api/axes_api.html)手动:

import matplotlib.pyplot as plt 
fig = plt.figure() 
ax = fig.add_subplot(111) 

rows = [] 
for x in range(0,14): 
    rows.append(['a',14-x]) 

df = pd.DataFrame(rows) 
# df = df.set_index(0) 
df.plot(ax=ax) 

ax.set_xticks(df.index) 
ax.set_xticklabels(list(df[0])) 

enter image description here

+0

它不会让我把xticks设置为一个字符串变量“ValueError:无法将字符串转换为浮动t:“ – Chris

+0

好吧,我不知道你在想什么,我不知道蜱和标签......没有,我帮不了你 –

+0

我认为你的ValueError来自你设置通过执行'df = df.set_index(0)'索引到字符串'a'' –