Skip to content
Advertisement

Altair limit number of bars in facet chart

Suppose that I have a pandas dataframe like this one:

JavaScript

I want to make a bar chart with altair, where the height of the bars is counts, and the label is the label. I want to add a facet by the column group. How do I limit the number of bars to be shown, if I want the top 3 counts for each sub-chart?

Hopefully I’d like to do this without performing operations in pandas on the dataframe, and instead do them with the altair tools at hand.

Advertisement

Answer

You can do this using the same approach as in Altair limit number of bars, but use the groupby argument in the window transform:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement