在直方图matplotlib中绘制x-ticks [英] Plot x-ticks in histogram matplotlib
本文介绍了在直方图matplotlib中绘制x-ticks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想绘制给定名称的对应x.
我的意思是,对于foo
,它必须以直方图的形式绘制[10,20,30]
,并且所有foo,bar和baz都必须位于同一
I would like to plot the corresponding x for a given name.
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 :) )
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()
这篇关于在直方图matplotlib中绘制x-ticks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文