3

我期待創建一個很像nltk的詞法分散圖的圖表,但是我正在繪製一個空白的如何構建這個圖表。我在想分散是我最好的幾何,用'|'作爲標記,並設置alpha,但我遇到了各種設置參數的問題。這樣的一個例子是下面:熊貓散點圖分類和時間軸

enter image description here

我有佈置成與日期時間指數,頻率=「d」的數據幀,在5年的時間,並且每列表示使用的特定詞的計數日期。 例如:

tst = pd.DataFrame(index=pd.date_range(datetime.datetime(2010, 1, 1), end=datetime.datetime(2010, 2, 1), freq='D'), data=[[randint(0, 5), randint(0, 1), randint(0, 2)] for x in range(32)]) 

目前,我想要一個類似於以下內容:

plt.figure() 
tst.plot(kind='scatter', x=tst.index, y=tst.columns, marker='|', color=sns.xkcd_rgb['dodger blue'], alpha=.05, legend=False) 
yticks = plt.yticks()[0] 
plt.yticks(yticks, top_words) 

上面的代碼產生一個KeyError異常:

KeyError: "['2009-12-31T19:00:00.000000000-0500' '2010-01-01T19:00:00.000000000-0500'\n '2010-01-02T19:00:00.000000000-0500' '2010-01-03T19:00:00.000000000-0500'\n '2010-01-04T19:00:00.000000000-0500' '2010-01-05T19:00:00.000000000-0500'\n '2010-01-06T19:00:00.000000000-0500' '2010-01-07T19:00:00.000000000-0500'\n '2010-01-08T19:00:00.000000000-0500' '2010-01-09T19:00:00.000000000-0500'\n '2010-01-10T19:00:00.000000000-0500' '2010-01-11T19:00:00.000000000-0500'\n '2010-01-12T19:00:00.000000000-0500' '2010-01-13T19:00:00.000000000-0500'\n '2010-01-14T19:00:00.000000000-0500' '2010-01-15T19:00:00.000000000-0500'\n '2010-01-16T19:00:00.000000000-0500' '2010-01-17T19:00:00.000000000-0500'\n '2010-01-18T19:00:00.000000000-0500' '2010-01-19T19:00:00.000000000-0500'\n '2010-01-20T19:00:00.000000000-0500' '2010-01-21T19:00:00.000000000-0500'\n '2010-01-22T19:00:00.000000000-0500' '2010-01-23T19:00:00.000000000-0500'\n '2010-01-24T19:00:00.000000000-0500' '2010-01-25T19:00:00.000000000-0500'\n '2010-01-26T19:00:00.000000000-0500' '2010-01-27T19:00:00.000000000-0500'\n '2010-01-28T19:00:00.000000000-0500' '2010-01-29T19:00:00.000000000-0500'\n '2010-01-30T19:00:00.000000000-0500' '2010-01-31T19:00:00.000000000-0500'] not in index" 

任何幫助,將不勝感激。

的幫助,我是能夠產生如下:

plt.plot(tst.index, tst, marker='|', color=sns.xkcd_rgb['dodger blue'], alpha=.25, ms=.5, lw=.5) 
plt.ylim([-1, 20]) 
plt.yticks(range(20), top_words) 

enter image description here

不幸的是,它只是似乎是上條將顯示當存在要在上面建了相應的條的。這不是我數據的外觀。

回答

1

我不確定你可以用.plot方法做到這一點。然而,很容易筆直地做在matplotlib

plt.plot(tst.index, tst, marker='|', lw=0, ms=10) 
plt.ylim([-0.5, 5.5]) 

enter image description here

+0

預期一樣幾乎一模一樣。儘管如此,我的確有一些轉變。我的0的參數在底部形成一個小條,其中每一個整數形成一條直線。我會在我的問題中發佈結果。 – hyleaus

1

如果你可以安裝seaborn,嘗試stripplot():

import seaborn as sns 
sns.stripplot(data=tst, orient='h', marker='|', edgecolor='blue'); 

plot

注意,我改變你的數據,使其看起來更有趣:

在seaborn
tst = pd.DataFrame(index=pd.date_range(datetime.datetime(2010, 1, 1), end=datetime.datetime(2010, 2, 1), freq='D'), 
        data=(150000 * np.random.rand(32, 3)).astype('int')) 

的更多信息:

http://stanford.edu/~mwaskom/software/seaborn/tutorial/categorical.html

+0

是的,這工作得很好。我在文檔中遇到過這個模塊,但之前無法訪問它。我使用的是過時的seaborn版本。感謝您的建議! – hyleaus

+0

不過,我想說的是,底部的比例應該是閱讀日期。從我的原始數據集中,散點應該位於列和索引的交點處,並且根據數據的程度使點變暗。 – hyleaus