Home > database >  How to make a multi-level chart column label
How to make a multi-level chart column label

Time:09-16

I stopped at this point:

df = pd.DataFrame({'id': [1, 2, 3],
               'users': [40, 2, 51],
               'buyers': [15, 1, 29],
               'percentage': [37.5000, 50.0000, 56.8627]})

fig, ax = plt.subplots(figsize=(10, 6))

# Plot the all users
sns.barplot(x='id', y='users', data=df, palette='Blues', edgecolor='grey', alpha=0.7)
# Plot the buyers
sns.barplot(x='id', y='buyers', data=df, palette='Blues', edgecolor='black', hatch='//')

# display column values
for container in ax.containers:
    ax.bar_label(container, fontsize=13)
plt.show()

The chart looks like this:

enter image description here

I also need to include data from the "percentage" frame in the shaded portion of the chart. Please tell me how to do it. Thanks

CodePudding user response:

  • Add the 'percentage' values by passing a custom list to the labels= parameter in .bar_label
    • Use enter image description here

  • Related