gpt4 book ai didi

python - 在直方图中绘制 x-ticks matplotlib

转载 作者:太空狗 更新时间:2023-10-30 02:32:06 25 4
gpt4 key购买 nike

我想绘制给定名称对应的 x。我的意思是,对于 foo,它必须以直方图的形式绘制 [10,20,30],并且所有 foo、bar、baz 都需要在同样graph .(我不需要 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()

enter image description here

关于python - 在直方图中绘制 x-ticks matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19963054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com