簡體   English   中英

如何使用 seaborn 將 plot 堆疊條形圖與多個變量

[英]How to plot a stacked bar chart with multiple variables with seaborn

我有一個數據集,如下所示:

Season  Phylum          Assigned    Yield
1   Acidobacteria       157363      High
1   Ignavibacteriae     15158       Low
1   Gemmatimonadetes    16408       High
2   Actinobacteria      143507      High
2   Chloroflexi         252391      Low
3   Cyanobacteria       172041      High
3   Firmicutes          74769       High
3   Acidobacteria       222991      Low
3   Bacteroidetes       280246      Low

但是,我使用此代碼未能實現我想要的 plot

import matplotlib.pyplot as plt
from matplotlib.ticker import PercentFormatter, MultipleLocator
import seaborn as sns
import pandas as pd

df = pd.read_csv("./bacterial_phylum_abundance_root_allseasons.csv",sep='\t')
print(df)

sns.set_style('whitegrid')
g = sns.displot(data=df, x='Yield', hue='Phylum', col='Season', multiple='fill', shrink=0.7, palette='turbo')
g.set(xlabel='', ylabel='')
g.axes[0, 0].yaxis.set_major_locator(MultipleLocator(.1))
g.axes[0, 0].yaxis.set_major_formatter(PercentFormatter(1))
g.axes[0, 0].set_xlim(-.6, 1.6)
sns.despine(left=True)
plt.subplots_adjust(wspace=0)
plt.show()

我想制作一個看起來像這樣的堆疊條形圖,其中包括整個季節(1、2、3):在此處輸入圖像描述

如果有人可以幫助我,我真的很感激。

先感謝您

感謝您的回復。 下面是我的代碼的 output。但是,它不反映每個門的“Assinged”值

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM