Plot x-ticks in histogram matplotlib

一曲冷凌霜 提交于 2019-12-05 18:15:02

Hope this helps you:

from matplotlib import pyplot as plt
import numpy as np

names = ['foo', 'bar', 'baz']
x  = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]
colors = ['crimson', 'burlywood', 'chartreuse']

y = zip(*x)
groups = len(x)
members = len(y)
pos = np.arange(groups)
width = 1. / (1 + members)

fig, ax = plt.subplots()    
for idx, (serie, color) in enumerate(zip(y, colors)):
    ax.bar(pos + idx * width, serie, width, color=color)

ax.set_xticks(pos + width)
ax.set_xticklabels(names)

plt.show()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!