alt.Repeat - create a grid of charts
See original GitHub issueHi Jake,
In the docs you have a nice repeating example that I am trying to learn from. But suppose I have a simple dataFrame like this:
df=pd.DataFrame({'year': [1,2,3], 'school 1': [10,20,30], 'school 2': [15,6,25], 'school 3': [120,202,302], 'school 4': [152,6,225]})
and I would like a 2x2 grid where for each chart “year” is on the x axis and each charts show a line for a given school. So basically, one field is held constant. I can accomplish this by doing the following, but is there a better, more “Altair-ic” way to do this?
y1=alt.Chart().mark_line(point=True).encode(
x='year',
y='school 1',
)
y2=alt.Chart().mark_line(point=True).encode(
x='year',
y='school 2',
)
y3=alt.Chart().mark_line(point=True).encode(
x='year',
y='school 3',
)
y4=alt.Chart().mark_line(point=True).encode(
x='year',
y='school 4',
)
alt.vconcat((y1|y2), (y3|y4), data=df)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Compound Charts: Layer, HConcat, VConcat, Repeat, Facet
In this example, we explicitly loop over different x and y encodings to create a 2 x 2 grid of charts showing different...
Read more >Repeated graph in altair - python - Stack Overflow
If you get empty graphs in a repeat chart, it usually means one of two things: your data is not accessible by the...
Read more >altair line up concatenated charts into a grid - You.com
The columns argument can be similarly specified for concatenated charts in alt.concat() and repeated charts alt.Chart.repeat() . Open side panel.
Read more >Compound Charts: Layer, HConcat, VConcat, Repeat, Facet
Along with the basic Chart object, Altair provides a number of compound plot types that can be used to create stacked, layered, faceted,...
Read more >Multi-View Composition - Nextjournal
repeat : take a base chart specification and apply it to multiple data ... The two can be used together to create a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone looking for an example until this functionality is in VL/Altair. There are various solutions here and my attempt is the following. Note that the DataFrame in this case has three columns and is in long form (see
df.melt
)I haven’t seen this documented on SO or GitHub issues, but one can also use
repeat
instead ofcolumn
orrow
withinrepeat
: