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