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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 matplotlib 條形圖中區(qū)分特定的 x 條形顏色?

如何在 matplotlib 條形圖中區(qū)分特定的 x 條形顏色?

明月笑刀無情 2021-12-29 19:51:26
我目前正在制作一個程序,其中一個酒吧是為客戶服務(wù)的。我希望這個酒吧用不同的顏色來區(qū)分。我曾經(jīng)通過遍歷字典 (barChartObjects) 來做到這一點,當(dāng)字典的鍵與參數(shù)(公司)匹配時,它會改變顏色。發(fā)生這種情況是因為它單獨繪制了每個條形并且運行良好。由于標(biāo)簽的格式問題,我不得不改變我顯示圖形的方式,現(xiàn)在我對如何用我的新功能做我以前所做的事情感到困惑。def plotCompany(barChartObjects, company):    # axis of data    x = []    y = []    print("Company: " + company)    # date for the file output name    dateForOutput = date.today()    # append the attributed input to the corresponding axis    for key, value in barChartObjects.items():        x.append(key)        y.append(value)    freq_series = pd.Series.from_array(y)    # Plot the figure.    plt.figure(figsize=(12, 8))    # this is where I set the color for the graph, I am assuming I will need to change something here    ax = freq_series.plot(kind='bar', color= "#36C989")    ax.set_title("Total Shareholder Return (" + (date.today()-timedelta(days=30)).strftime("%b %d %Y") + ")")    ax.set_xlabel("Companies")    ax.set_ylabel("Percent Change")    ax.set_xticklabels(x)    plt.text(-0.25, 12, "Median: " + str(medianCalc(barChartObjects)) + "%")    add_value_labels(ax)    # save the file to my directory.    plotDirectory = config.getDirectory(company)    plt.savefig(plotDirectory, quality = 95)    plt.show()    return plotDirectory以上是我的功能目前的設(shè)置方式。作為參考,下面是我以前使用的函數(shù),它正確地為它們著色,但格式古怪,因此我使用了這個新函數(shù)。
查看完整描述

1 回答

?
慕田峪9158850

TA貢獻1794條經(jīng)驗 獲得超8個贊

這兩種方法看起來都很復(fù)雜。如果我理解正確,您想根據(jù) x 軸類別繪制帶有顏色的分類條形圖。舉個例子:


import matplotlib.pyplot as plt


companies = ["Company A", "Company B", "Company C", "Company D"]

values = [17, 23, 12, 32]


myclient = "Company B"

colors = ["grey" if company is not myclient else "red" for company in companies]


plt.bar(companies, values, color=colors)


plt.show()

http://img1.sycdn.imooc.com//61cc4c170001199805960228.jpg

查看完整回答
反對 回復(fù) 2021-12-29
  • 1 回答
  • 0 關(guān)注
  • 241 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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