第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何顯示多個(gè)字典的matplotlib條形圖中每列的總計(jì)數(shù)?

如何顯示多個(gè)字典的matplotlib條形圖中每列的總計(jì)數(shù)?

牛魔王的故事 2023-07-05 17:58:13
我的代碼:import numpy as npimport matplotlib.pyplot as plt#sample dataME_Requests = {'John Doe': 47, 'Amanda Doe': 27, 'Maria Doe': 26}non_ME_Requests = {'John Doe': 105, 'Amanda Doe': 64, 'Maria Doe': 48}month="Apr-2020"X = np.arange(len(ME_Requests))ax = plt.subplot(111)ax.bar(X, ME_Requests.values(), width=0.2, align='center')ax.bar(X-0.2, non_ME_Requests.values(), width=0.2, align='center')ax.legend(('ME_Requests','non_ME_Requests'))plt.xticks(X, ME_Requests.keys())plt.title("Emails Closed per team member in {}".format(month) , fontsize=17)plt.savefig('img.png')plt.show()我目前的條形圖:期望的輸出:我正在嘗試以下操作:#sample dataME_Requests = {'John Doe': 47, 'Amanda Doe': 27, 'Maria Doe': 26}non_ME_Requests = {'John Doe': 105, 'Amanda Doe': 64, 'Maria Doe': 48}month="Apr-2020"x = np.arange(len(month))  # the label locationswidth = 0.35  # the width of the barsfig, ax = plt.subplots()rects1 = ax.bar(X, ME_Requests.values(), width=0.2, align='center')rects2 = ax.bar(X-0.2, non_ME_Requests.values(), width=0.2, align='center')# Add some text for labels, title and custom x-axis tick labels, etc.ax.set_ylabel('# Requests')ax.set_title("Emails Closed per team member in {}".format(month) , fontsize=17)ax.set_xticks(X, ME_Requests.keys())ax.set_xticklabels(month)ax.legend(('ME_Requests','non_ME_Requests'))def autolabel(rects):    """Attach a text label above each bar in *rects*, displaying its height."""    for rect in rects:        height = rect.get_height()        ax.annotate('{}'.format(height),                    xy=(rect.get_x() + rect.get_width() / 2, height),                    xytext=(0, 3),  # 3 points vertical offset                    textcoords="offset points",                    ha='center', va='bottom')autolabel(rects1)autolabel(rects2)fig.tight_layout()plt.show()但是存在一個(gè)問題,因?yàn)樗粫?huì)顯示用戶名(John Doe 等),而是顯示“p”或“r”等。請(qǐng)參見下文:有人可以幫我解決這個(gè)問題嗎?提前致謝!
查看完整描述

1 回答

?
神不在的星期二

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊

ax.set_xticklabels(month)應(yīng)替換為 ax.set_xticklabels(ME_Requests.keys()).


要將標(biāo)簽放在條形之間,您可以減去width/2左側(cè)X條形的標(biāo)簽,并添加width/2右側(cè)X條形的標(biāo)簽。ax.tick_params(axis='x', length=0)可以使用去除刻度線。


import numpy as np

import matplotlib.pyplot as plt


# sample data

ME_Requests = {'John Doe': 47, 'Amanda Doe': 27, 'Maria Doe': 26}

non_ME_Requests = {'John Doe': 105, 'Amanda Doe': 64, 'Maria Doe': 48}

month = "Apr-2020"

X = np.arange(len(ME_Requests))

fig, ax = plt.subplots()

rects1 = ax.bar(X + 0.1, ME_Requests.values(), width=0.2, align='center')

rects2 = ax.bar(X - 0.1, non_ME_Requests.values(), width=0.2, align='center')

ax.legend(('ME_Requests', 'non_ME_Requests'))

ax.set_xticks(X)

ax.set_xticklabels(ME_Requests.keys())

ax.set_title(f"Emails Closed per team member in {month}", fontsize=17)

ax.tick_params(axis='x', length=0)


def autolabel(rects):

    """Attach a text label above each bar in *rects*, displaying its height."""

    for rect in rects:

        height = rect.get_height()

        ax.annotate(f'{height:.0f}',

                    xy=(rect.get_x() + rect.get_width() / 2, height),

                    xytext=(0, 3),  # 3 points vertical offset

                    textcoords="offset points",

                    ha='center', va='bottom')


autolabel(rects1)

autolabel(rects2)


fig.tight_layout()

plt.show()

http://img1.sycdn.imooc.com//64a53ef900013cf604330272.jpg

查看完整回答
反對(duì) 回復(fù) 2023-07-05
  • 1 回答
  • 0 關(guān)注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)