0

Sorry if this is a noob question, but I have never used pandas or seaborn before. I am trying to make a bar chart with stacked bars using the following;

'''

graph = seaborn.catplot(
    data=data, kind="bar",
    x="year", y="count", hue="name", height=20, palette=customPalette, 
    dodge = False
)

'''

However, not all of the results are visible, as some bars overlap and hide other bars. Viewing this with dodge = True clearly shows which bars overlap. How to I change the order of the bars for stacking?

The data looks like this:

name     decade     count
Anne     1920      70,000
Amy      1920      60,000
Ava      1920      50,000
Bill     1930      65,000
Bo       1930      55,000
And so on ...

When I run the code I want a bar chart, with each bar representing a different decade, and the bar split up to show the count of each name in that decade. However, looking at the bar produced for 1920, only Anne and Amy are visible, and the Ava bar is covered by the Amy bar. If I change dodge = False to True, I can see that the bars are ordered this way. How can I change the bars so they are ordered by size for visibility when stacking? I hope that makes sense.

  • Please create a [reprex] with sample data. – BigBen Mar 10 '21 at 17:16
  • Please edit your question if you want to add more information. – Mr. T Mar 10 '21 at 17:18
  • Hi, I edited my question with more info, but I do not know how I can provide an example because I do not know how to upload images. – user5740534 Mar 10 '21 at 17:24
  • The current versions of seaborn don't support stacked bars yet. So, you either need `dodge=True`, or create multiple `sns.barplot` setting as `bottom` the total of the previous "layer". Or use pandas' barplot. – JohanC Mar 10 '21 at 17:26
  • See e.g [Stacked bar chart in Seaborn](https://stackoverflow.com/questions/59038979/stacked-bar-chart-in-seaborn) – JohanC Mar 10 '21 at 17:28

0 Answers0