Skip to content

Format the text output of so.Text() #3142

Answered by mwaskom
FirefoxMetzger asked this question in Q&A
Discussion options

You must be logged in to vote

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 halign=df["Score"] > 70 you would have halign=lambda: "Score > 70". and instead of text=df["Score"].round(1) you'd have text=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…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@FirefoxMetzger
Comment options

Answer selected by FirefoxMetzger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3139 on November 14, 2022 23:19.