Reputation: 63
How to split Altair .facet chart into individual images with option to save each one.
is it possible to save individual images when using .facet?
provided basic example of .facet chart with image save option for whole group.
(Screenshot from https://altair-viz.github.io/user_guide/compound_charts.html#faceted-charts)
Upvotes: 1
Views: 206
Reputation: 86523
You can only save full charts; there is no mechanism to individually save subpanels of a single chart.
As a workaround, you can re-create these subpanels as single charts. Here is one possible approach using a conditional opacity:
import altair as alt
from vega_datasets import data
iris = data.iris()
chart = alt.Chart(iris).mark_point().encode(
x='petalLength:Q',
y='petalWidth:Q',
color='species:N'
).properties(
width=160,
height=160
)
for species in ['setosa', 'versicolor', 'virginica']:
chart.encode(
opacity=alt.condition(
f"datum.species == '{species}'", alt.value(1), alt.value(0)
)
).display()
Upvotes: 2