2
我有一個Counter對象。我想繪製一個這樣的水平條形圖http://matplotlib.org/examples/lines_bars_and_markers/barh_demo.html如何繪製水平條形圖中的Counter對象?
我該怎麼做?
我有一個Counter對象。我想繪製一個這樣的水平條形圖http://matplotlib.org/examples/lines_bars_and_markers/barh_demo.html如何繪製水平條形圖中的Counter對象?
我該怎麼做?
這是從頁的例子中你提到修改爲使用計數器對象:
"""
Simple demo of a horizontal bar chart.
"""
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
# Counter data, counter is your counter object
keys = counter.keys()
y_pos = np.arange(len(keys))
# get the counts for each key, assuming the values are numerical
performance = [counter[k] for k in keys]
# not sure if you want this :S
error = np.random.rand(len(keys))
plt.barh(y_pos, performance, xerr=error, align='center', alpha=0.4)
plt.yticks(y_pos, keys)
plt.xlabel('Counts per key')
plt.title('How fast do you want to go today?')
plt.show()
什麼,如果你想進行排序的值的鑰匙? – Tgsmith61591