-
Hi, For the objects interface is it possible to center the texts inside the stacked bars? See the link below for examples. Thank you. https://stackoverflow.com/questions/41296313/stacked-bar-chart-with-centered-labels MWE: import pandas as pd
import seaborn.objects as so
df = pd.DataFrame(data={'a': [45, 17, 47],
'b': [91, 70, 72],
'c': [68, 43, 13],
'group': ['x', 'y', 'z'],
}
)
(
so.Plot(df.melt(id_vars='group'),
x="group", y="value", color="variable", text="value")
.add(so.Bar(), so.Stack())
.add(so.Text(color="k", valign="top"), so.Stack())
) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Currently no this is not possible, and it does not seem like a trivial feature either since this requires knowing where the middle of the bars is when creating the matplotlib text objects. But there may be a way to modify the |
Beta Was this translation helpful? Give feedback.
-
Well, I actually needed this myself so I went ahead and coded it ; this requires a custom object replacing Stack but outputting the middle "y" values.
You can use it by replacing |
Beta Was this translation helpful? Give feedback.
That makes sense. It works now. Thank you! For future reference below is the complete example.