[英]Plot x-ticks in histogram matplotlib
I would like to plot the corresponding x for a given name. 我想为给定的名称绘制相应的x。 by that I mean, for foo
it has to plot [10,20,30]
in the form of a histogram and all foo, bar, baz need to be in the same graph .(I don't require 3d :) ) 我的意思是,对于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()
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.