Format the text output of so.Text() #3142
-
Is it possible to apply post-processing to the value displayed by I would like to do two things:
Sidenote: I am a big fan of the flexibility of the objects API 🚀 though I must admit I haven't fully understood the intuition behind it yet, so it could very well be that this feature exists and that I just missed it in the docs because I've searched the wrong places. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Here's what I would do right now df = sns.load_dataset("glue").groupby("Model")[["Score"]].mean()
(
so.Plot(
df,
x="Score",
y="Model",
text=df["Score"].round(1),
halign=df["Score"] > 70,
)
.add(so.Bar())
.add(so.Text(), color=df["Score"] > 70)
.scale(color=["b", "w"])
) I think that some aspects of this will get cleaner with #3107, e.g. instead of Format is a little trickier and I wouldn't say I'm against having a format property for the text mark, but there are enough annoying open questions (what is the default? how does the mapping work?) that I'm holding off for now. |
Beta Was this translation helpful? Give feedback.
Here's what I would do right now
I think that some aspects of this will get cleaner with #3107, e.g. instead of
halign=df["Score"] > 70
you would havehalign=lambda: "Score > 70"
. and instead oftext=df["Score"].round(1)
you'd havetext=lambda: "Score.round(1)"
.Format is a little trickier and I wouldn't say I'm against having a format property for the text mark, but there are enough annoying op…