我有一個包含1000個元素及其各自的頻率的數據集。我需要繪製排名前10的元素的直方圖。
我所做的:無法使用彈性類型執行縮小plt.hist
top_words = Counter(my_data).most_common()
top_words_10 = top_words[:10]
plt.hist(top_words_10,label='True')
,並得到這個錯誤:
TypeError
Traceback (most recent call last)
<ipython-input-29-ff974b3a2354> in <module>()
5 print top_words[:10]
6
----> 7 plt.hist(top_words_10)
C:\Anaconda\lib\site-packages\numpy\core\_methods.pyc in _amin(a, axis, out, keepdims)
12 def _amin(a, axis=None, out=None, keepdims=False):
13 return um.minimum.reduce(a, axis=axis,
---> 14 out=out, keepdims=keepdims)
15
16 def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
TypeError: cannot perform reduce with flexible type
任何想法?我的數據是這樣的:
[(' whitefield', 65299), (' bellandur', 57061), (' kundalahalli', 51769), (' marathahalli', 50639), (' electronic city', 44041), (' sarjapur road junction', 34164), (' indiranagar 2nd stage', 32459), (' malleswaram', 32171), (' yelahanka main road', 28901), (' domlur', 28869)]
thanx a ton ..it works awesome ..我怎麼能交換軸???我想它在垂直方式..並pleaase解釋for循環.. –
看到這個答案[link](http://stackoverflow.com/questions/17074772/using-text-on-y-axis-in-matplotlib- INSTEAD-OF-數)。在for循環中,我只是用元組解析列表:'('whitefield',65299)',通過索引獲取元素並將它們存儲在列表中。 –
應該有一些圖表將分類值列表作爲輸入並繪製計數。這應該是開箱即用的,它是人們可以想象的最簡單的圖表。 – ketan