Skip to content
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

Adding titles to a grouped bar chart #3392

Open
amandaha8 opened this issue Apr 2, 2024 · 2 comments
Open

Adding titles to a grouped bar chart #3392

amandaha8 opened this issue Apr 2, 2024 · 2 comments
Labels

Comments

@amandaha8
Copy link

What happened?

I'm using the dataset "source" in the grouped bar chart example. I'd like to add a title above the X-Axis title of "Category" that indicates this graph is grouped by the column "Group." However, when I edit the code following this page, no title pops up.

alt.Chart(source).mark_bar().encode(
    x="Category:N",
    y="Value:Q",
    xOffset=alt.X("Group:N", title = "Groups")
    color="Group:N"
)

What would you like to happen instead?

No response

Which version of Altair are you using?

'5.1.1'

@amandaha8 amandaha8 added the bug label Apr 2, 2024
@mattijn
Copy link
Contributor

mattijn commented Apr 2, 2024

Thanks for reporting! This indeed seems like a mismatch between the documentation and the actual behavior. My gut-feeling is that the behavior is right and that the documentation should not include title as a valid option (through the jsonschema defintion). But this requires more investigation.

For now, you could use the following solution:

import altair as alt
import pandas as pd

source = pd.DataFrame({
    "Category":list("AAABBBCCC"),
    "Group":list("xyzxyzxyz"),
    "Value":[0.1, 0.6, 0.9, 0.7, 0.2, 1.1, 0.6, 0.1, 0.2]
})

alt.Chart(source).mark_bar().encode(
    x=alt.X("Category:N", title=["Categories", "Grouped by column 'Group'"]),
    y="Value:Q",
    xOffset=alt.XOffset("Group:N", title='this does not have impact'),
    color="Group:N"
)

image

Thanks again for the report!

@amandaha8
Copy link
Author

Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants