簡體   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