How to format row or column as percent #3131
-
ProblemHow do you format the title of row or column facets as percent? For normal axes it's MWEimport altair as alt
import pandas as pd
source = pd.DataFrame(
[
{"a": "a1", "b": "b2", "c": "z", "p": "0.55"},
{"a": "a1", "b": "b3", "c": "y", "p": "0.58"},
{"a": "a2", "b": "b3", "c": "x", "p": "0.74"},
{"a": "a2", "b": "b3", "c": "y", "p": "0.64"},
]
)
alt.Chart(source, width=60, height=alt.Step(8)).mark_bar().encode(
alt.Y("c:N").axis(None),
alt.X("a:N").title("Factor A"),
alt.Color("c:N").title("settings").legend(orient="bottom", titleOrient="left"),
alt.Row("p:Q"),
# alt.Row("p:Q").axis(format="%"),
alt.Column("b:N").title("Factor B"),
).save("test.png") This graph makes no sense; I reached for the quickest example to modify. |
Beta Was this translation helpful? Give feedback.
Answered by
joelostblom
Aug 4, 2023
Replies: 2 comments 3 replies
-
You can use |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
mcp292
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
header
instead ofaxis
. Note that it seems like you also need to round the percentage so something like this would workalt.Row("p:Q").header(format=".0%")
: