我想绘制给定名称的对应x。我的意思是,因为foo
它必须以[10,20,30]
直方图的形式绘制,并且所有foo,bar,baz都必须在同一张图中。(我不需要3d :))
import pylab as P
name = ['foo', 'bar', 'baz']
x = [[10,20,30],[40,50,60],[70,80,90]]
P.figure()
P.hist(x, 10, histtype='bar',
color=['crimson', 'burlywood', 'chartreuse'],
label=['Crimson', 'Burlywood', 'Chartreuse'])
P.show()
希望这对您有帮助:
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()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句