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

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

Seaborn 條形圖圖例標簽失去顏色

Seaborn 條形圖圖例標簽失去顏色

縹緲止盈 2021-09-14 17:39:24
我有一個 seaborn boxplot,當我嘗試使用 plt.legend("Strings") 更改標簽名稱時,它會丟失標簽的顏色。我需要在保持顏色編碼的同時更改標簽,但在搜索答案后我不知道如何執(zhí)行此操作。色調圖例 1-4 對應于 1 = 對政治非常感興趣到 4 = 完全不感興趣。我想將圖例色調標簽從 1-4 更改為他們對政治的興趣程度。我的代碼是:套餐import pandas as pdimport numpy as npimport seaborn as snsimport matplotlib.pyplot as plt我不知道如何以更簡單的方式創(chuàng)建數(shù)據(jù)框,所以我這樣做了a1 = {'Reads Newspapers': 0, 'Interest in Politics': 1}a2 = {'Reads Newspapers': 0, 'Interest in Politics': 2}a3 = {'Reads Newspapers': 0, 'Interest in Politics': 3}a4 = {'Reads Newspapers': 0, 'Interest in Politics': 4}b1 = {'Reads Newspapers': 1, 'Interest in Politics': 1}b2 = {'Reads Newspapers': 1, 'Interest in Politics': 2}b3 = {'Reads Newspapers': 1, 'Interest in Politics': 3}b4 = {'Reads Newspapers': 1, 'Interest in Politics': 4}df1 = pd.DataFrame(data=a1, index=range(1))df1 = pd.concat([df1]*23)df2 = pd.DataFrame(data=a2, index=range(1))df2 = pd.concat([df2]*98)df3 = pd.DataFrame(data=a3, index=range(1))df3 = pd.concat([df3]*99)df4 = pd.DataFrame(data=a4, index=range(1))df4 = pd.concat([df4]*18)b1 = pd.DataFrame(data=b1, index=range(1))b1 = pd.concat([b1]*468)b2 = pd.DataFrame(data=b2, index=range(1))b2 = pd.concat([b2]*899)b3 = pd.DataFrame(data=b3, index=range(1))b3 = pd.concat([b3]*413)b4 = pd.DataFrame(data=b4, index=range(1))b4 = pd.concat([b4]*46)data = pd.concat([df1,df2,df3,df4,b1,b2,b3,b4])產生錯誤的實際繪圖plt.figure(figsize=(10,8))g = sns.barplot(data=data, x='Reads Newspapers', estimator=len,y='Interest in Politics', hue='Interest in Politics' )plt.ylabel("Sample Size")ax = plt.subplot()ax = ax.set_xticklabels(["No","Yes"])#plt.legend(["very interested","somewhat interested", "only a little interested", "not at all interested "],)#plt.savefig('Newspaper policy')我嘗試使用,plt.legend但是當我這樣做時,圖例標簽會失去顏色,因此它變成了沒有顏色關聯(lián)的字符串,使其比以前更糟。我現(xiàn)在已經編輯了我的整個腳本。https://github.com/HenrikMorpheus/Newspaper-reading-survey/blob/master/politicalinterest.ipynb 由于某種我不知道的原因加載了錯誤,但您應該能夠在 jupyter 中打開筆記本。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 338 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號