-
-
Notifications
You must be signed in to change notification settings - Fork 826
Closed as not planned
Labels
Description
Suggestion
Is there a nice way to customise properties of faceted (or repeated) plots using other variables in the dataframe besides the faceting one?
Assigning other parameters as vectors or dataframe column names instead of having to manually assemble the plots in a loop would be very convenient and intuitive.
Simple example using code from the faceting documentation: setting the sizes and colours of subplot titles
import altair as alt
from vega_datasets import data
iris = data.iris.url
alt.Chart(iris).mark_point().encode(
x = 'petalLength:Q',
y = 'petalWidth:Q',
color = 'species:N'
).properties(
width = 180,
height = 180
).facet(
alt.Facet('species:N',
# Having arguments accept column names or iterables of the same length would be very intuitive
header = alt.Header(labelFontSize = 'font_size_column:Q', labelColor = ['red', 'green', 'blue']),
title = 'titles_column:N'), # or similar
# ...
# Currently accepting only scalars
# header = alt.Header(labelFontSize = 17, labelColor = 'red'), # e.g. specify individual font sizes and colours for the headers
# title = 'Not the subplot titles'), # e.g. specify individual titles
columns = 4,
title = 'Not the subplot titles either'
)Current solution
The above example can be achieved simply enough by manually assembling the subplots, but the situation can get complicated for more elaborate compound charts and datasets, and having intuitive options in the facet block would be very convenient.
import altair as alt
from vega_datasets import data
iris = data.iris.url
base = alt.Chart(iris).mark_point().encode(
x = 'petalLength:Q',
y = 'petalWidth:Q',
color = 'species:N'
).properties(
width=160,
height=160
)
chart = alt.hconcat()
for species, title_colour in zip(['setosa', 'versicolor', 'virginica'], ['red', 'green', 'blue']):
chart |= base.transform_filter(alt.datum.species == species).properties(
title = alt.Title(species, fontSize = 17, color = title_colour))
chart