Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在水平条形图中绘制计数器对象?_Python_Python 3.x_Matplotlib_Counter - Fatal编程技术网

Python 如何在水平条形图中绘制计数器对象?

Python 如何在水平条形图中绘制计数器对象?,python,python-3.x,matplotlib,counter,Python,Python 3.x,Matplotlib,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 coun

我有一个反对的对象。我想画一个这样的水平条形图


如何才能做到这一点?

这是您提到的页面中的示例,该页面已修改为使用计数器对象:

 """
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()

如果要按值对键进行排序,该怎么办?