Skip to content

Simpler way to achieve labelled bar graph #2988

Answered by joelostblom
mcp292 asked this question in Q&A
Discussion options

You must be logged in to vote

You will need to layer two marks to have both bars and text in the same chart. Having that said, the syntax of the example you linked could be more succinct:

bars = alt.Chart(source).mark_bar().encode(
    x='wheat',
    y="year:O",
    text='wheat'
)

bars + bars.mark_text(align='left', dx=1)

This looks pretty readable to me, but I'm curious to hear what you had in mind for the syntax and if you have encountered issues with the layering approach.

Replies: 1 comment 14 replies

Comment options

You must be logged in to vote
14 replies
@mcp292
Comment options

@joelostblom
Comment options

@mattijn
Comment options

@joelostblom
Comment options

@mcp292
Comment options

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