繁体   English   中英

如何使用 matplotlib 绘制多个条形图 plot

[英]how to draw multiple bar plot using matplotlib

我有这个数组来创建一个多条 plot,

[
    ['n', 1, 2556], 
    ['n', 2, 21484], 
    ['n', 3, 11488], 
    ['o', 1, 602], 
    ['o', 2, 4708], 
    ['o', 3, 3006], 
    ['t', 1, 21966], 
    ['t', 2, 122067], 
    ['t', 3, 72724]
]

这是我期待画的,

在此处输入图像描述

现在我该如何用matplotlib做到这一点?,我尝试了一些他们没有用的东西

尝试这个,...

import matplotlib.pyplot as plt
import numpy as np


labels = ['n', '0', 'p']
men_means = [2000, 1000, 23000]
women_means = [20000, 4500, 120000]
women_meanT = [8000, 2500, 76000]

x = np.arange(len(labels))  # the label locations
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='1')
rects2 = ax.bar(x + width/2, women_means, width, label='2')
rects2 = ax.bar(x+width/2+width, women_meanT, width, label='3')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_xticks(x, labels)
ax.legend()
fig.tight_layout()

plt.show()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM