-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pct parameter in transform_calculate #10
Comments
Copying the code in question: import pandas as pd
import altair as alt
source = pd.DataFrame({'age': ['12', '32', '43', '54', '32', '32', '12']})
alt.Chart(source).transform_joinaggregate(
total='count(*)'
).transform_calculate(
pct='1 / datum.total'
).mark_bar().encode(
alt.X('age:Q', bin=True),
alt.Y('sum(pct):Q', axis=alt.Axis(format='%'))
)
No, that answer shows the best way to plot a histogram of percentages. |
Thank you for your prompt response! Is the creation of new fields that can be used as an encoding documented somewhere in the user guide? |
Yes, see the examples at https://altair-viz.github.io/user_guide/transform/calculate.html |
I'm trying to adapt the code from the following post: https://stackoverflow.com/questions/56358977/how-to-show-a-histogram-of-percentages-instead-of-counts-using-altair.
I looked through the documentation for the transform_calculate to find an explanation of the
pct
parameter but the search came up empty. Is it possible to update the documentation?Alternatively, is there a different/better way to plot a histogram of percentages instead of counts using Altair?
The text was updated successfully, but these errors were encountered: