2015-09-25 62 views
0

對我的ggplot圖有一些問題,因爲我似乎有很好的數據,但繪圖沒有取值。Python的ggplot沒有給出正確的y軸值?

下面是數據:

In[127]: ts_top10_stk 

Out[127]: 
       type value 
unit       
R084 entriesn_hourly 1868674 
R084 exitsn_hourly 1467338 
R022 entriesn_hourly 1773372 
R022 exitsn_hourly 1483494 
R012 entriesn_hourly 1618262 
R012 exitsn_hourly 1084521 
R046 entriesn_hourly 1555117 
R046 exitsn_hourly 968557 
R055 entriesn_hourly 1554806 
R055 exitsn_hourly 1174953 
R033 entriesn_hourly 1534652 
R033 exitsn_hourly 843390 
R018 entriesn_hourly 1444569 
R018 exitsn_hourly 1200120 
R011 entriesn_hourly 1355492 
R011 exitsn_hourly 484352 
R029 entriesn_hourly 1347727 
R029 exitsn_hourly 771924 
R179 entriesn_hourly 1270579 
R179 exitsn_hourly 415908 

下面是我用它做了一個情節:

plot_top10 = ggplot(aes(x = 'unit',y='value',fill='type'),data=ts_top10_stk) + geom_bar() 

獲取此異常:

Exception: Could not evaluate the 'x' mapping: 'unit' (original error: name 'unit' is not defined) 

顯然,我想創建一個堆疊的條形圖,其中x軸上的單位以及條目和出口之間的條形分開。我覺得我只是缺少ggplot的概念 - 因爲我根本無法獲得太多的工作。

下面是一些其他的信息:

In[202]: ts_top10_stk.columns 

Out[202]: Index([u'type', u'value'], dtype='object') 
In[203]: ts_top10_stk.index 
Out[203]: 
Index([u'R084', u'R084', u'R022', u'R022', u'R012', u'R012', u'R046', u'R046', 
     u'R055', u'R055', u'R033', u'R033', u'R018', u'R018', u'R011', u'R011', 
     u'R029', u'R029', u'R179', u'R179'], 
     dtype='object', name=u'unit') 

UPDATE:創建一個新列的單位價值:

ts_top10_stk['unit2'] = ts_top10_stk.index 
plot_top10 = ggplot(aes(x = 'unit2',y='value',fill='type'),data=ts_top10_stk) + geom_bar() 

這裏是我得到不過 - 還是不考慮實際值。 ..看起來像它只是一個計數和密謀(每個1,總共2種類型): enter image description here

回答

0

我還沒有在Python中使用ggplot這個消息讓我覺得它不知道在哪裏找到「單元」,因爲它不是一個列 - 它是熊貓的索引(這是一個熊貓物體吧?)嘗試製作一個獨立的「單元」列並重新做一遍?

+0

用你的建議更新了這個問題,但仍然得到不認可這些值的情節! – theStud54

+1

試試這個 - geom_bar(stat ='identity') – AustinC

+0

工作....我希望我知道爲什麼?那是什麼意思?並感謝奧斯汀! – theStud54