Hoping to get a pair of 100% stacked bar charts that looks like this:
What I have so far:
import pandas as pdimport numpy as npimport seaborn as snsimport matplotlib.pyplot as pltdfInd = pd.DataFrame({'Winner': ['Dog', 'Cat', 'Neither'],'percent_cum': [13, 48, 100],'y_value': ['1', '1', '1']})dfGen = pd.DataFrame({'Winner': ['Dog', 'Cat', 'Neither'],'percent_cum': [20, 53, 100],'y_value': ['2', '2', '2']})dfInd_1 = dfInd.iloc[[0]]dfInd_2 = dfInd.iloc[[1]]dfInd_3 = dfInd.iloc[[2]]dfGen_1 = dfGen.iloc[[0]]dfGen_2 = dfGen.iloc[[1]]dfGen_3 = dfGen.iloc[[2]]sns.set_theme(style="whitegrid")# Initialize the matplotlib figuref, ax = plt.subplots(figsize=(20, 15))sns.barplot(x="percent_cum", data=dfGen_3, color='#efedf5',ax=None)sns.barplot(x="percent_cum", data=dfGen_2, color='#bcbddc',ax=None)sns.barplot(x="percent_cum", data=dfGen_1, color='#756bb1',ax=None)sns.barplot(x="percent_cum", data=dfInd_3, color='#efedf5',ax=None)sns.barplot(x="percent_cum", data=dfInd_2, color='#bcbddc',ax=None)sns.barplot(x="percent_cum", data=dfInd_1, color='#756bb1',ax=None)
My problem: bar chart representing dfInd
is overlaid on dfGen
.
I've tried to solve by indicating the y_values for each dataframe (1 for dfInd
, 2 for dfGen
). My thinking was that this would shift dfInd
up the y axis by one. This didn't work: when I add sns.barplot(x="percent_cum", y="y_value",data=dfInd_1, color='#756bb1',ax=None)
I end up getting a big block.