Я пытаюсь создать пропорциональную гистограмму с накоплением с (6) категориями, сумма которых равна 100. У меня есть фрейм данных с несколькими значениями для каждого месяца года (n = 12) в каждая из шести категорий (C1, C2, C3, C4, C5, C6).
Я попробовал использовать matplotlib m.patches, чтобы собрать средние значения для каждого столбца, и получил график ниже. Я хочу сложить каждый стержень друг на друга. В настоящее время они расположены друг над другом.
Есть ли какие-нибудь простые дополнения/изменения, позволяющие складывать столбцы друг на друга?
Код и попытка построения столбчатой диаграммы:
# import libraries
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
df = pd.read_csv('marsh fig 7.csv')
plt.rcParams["axes.labelsize"] = 12
plt.figure(figsize=(600/my_dpi, 300/my_dpi), dpi=my_dpi)
bar1 = sns.barplot(x="Month", y="Percent_C1", data=df, color='darkgreen')
bar2 = sns.barplot(x="Month", y="Percent_C2", data=df, color='mediumseagreen')
bar3 = sns.barplot(x="Month", y="Percent_C3", data=df, color='goldenrod')
bar4 = sns.barplot(x="Month", y="Percent_C4", data=df, color='sienna')
bar5 = sns.barplot(x="Month", y="Percent_C5", data=df, color='steelblue')
bar6 = sns.barplot(x="Month", y="Component Proportion", data=df, color='darkblue')
# add legend
bar1 = mpatches.Patch(color='darkgreen', label='% C1')
bar2 = mpatches.Patch(color='mediumseagreen', label='% C2')
bar3 = mpatches.Patch(color='goldenrod', label='% C3')
bar4 = mpatches.Patch(color='sienna', label='% C4')
bar5 = mpatches.Patch(color='steelblue', label='% C5')
bar6 = mpatches.Patch(color='darkblue', label='% C6')
plt.ylim(0,40)
plt.text(0, 39, "Marsh", ha='left', va='top',fontsize=12, fontweight='normal', color="black")
ax2 = plt.twinx()
df2 = pd.read_csv('SRS1 Water Level.csv')
ax = sns.pointplot(x="Month", y="Water Depth (cm)", data=df2, color="black", linestyles=':', label=None, errwidth=1, capsize=0.2)
plt.legend(handles=[bar1, bar2, bar3, bar4, bar5, bar6])
plt.show()
Подробнее здесь: https://stackoverflow.com/questions/788 ... -in-python