How to annotate grouped bar plot with percent by hue/legend group

It’s typically not required to use seaborn to plot grouped bars, it’s just a matter of shaping the dataframe, usually with .pivot or .pivot_table. See How to create a grouped bar plot for more examples. Using pandas.DataFrame.plot with a wide dataframe will be easier, in this case, than using a long dataframe with seaborn.barplot, because … Read more

Grouped Bar graph Pandas

Using pandas: import pandas as pd groups = [[23,135,3], [123,500,1]] group_labels = [‘views’, ‘orders’] # Convert data to pandas DataFrame. df = pd.DataFrame(groups, index=group_labels).T # Plot. pd.concat( [df.mean().rename(‘average’), df.min().rename(‘min’), df.max().rename(‘max’)], axis=1).plot.bar()

Plot multiple columns of pandas DataFrame on the bar chart

Tested in python 3.11, pandas 1.5.1, matplotlib 3.6.2 Sample Data and Imports import pandas as pd import matplotlib.pyplot as plt import numpy as np np.random.seed(2022) # creates a consistent sample y = np.random.rand(10,4) y[:,0]= np.arange(10) df = pd.DataFrame(y, columns=[“X”, “A”, “B”, “C”]) X A B C 0 0.0 0.499058 0.113384 0.049974 1 1.0 0.486988 0.897657 … Read more

How to add percentages on top of grouped bars

The seaborn.catplot organizing function returns a FacetGrid, which gives you access to the fig, the ax, and its patches. If you add the labels when nothing else has been plotted you know which bar-patches came from which variables. From @LordZsolt’s answer I picked up the order argument to catplot: I like making that explicit because … Read more