2015-04-17 103 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'' –