Color problem when filtering two dimensions
![Uderman](https://us.v-cdn.net/6038102/uploads/defaultavatar/nLP0QHCLH24WL.jpg)
Hello.
I am getting started with Altair and playing aroung with the Gapminder dataset.
I have done a few charts with some selection parameters and filter transfers, so I can select both countries and clusters and get the other charts filtered and or color / opacity encoded.
It seens to work fine at begining, but I am having problens when I first filter the cluster and then a country. Somehow, all colors turn to blue, a default color.
Here is the code:
# Inicial imports and definition import altair as alt from vega_datasets import data gapminder = data.gapminder() #Selections clusterSelection = alt.selection_point(fields=['cluster']) countrySelection = alt.selection_point(fields=['country']) #BarCharts baseBars = alt.Chart(gapminder).mark_bar() #Clusters overviewBase = baseBars.encode( x=alt.X('cluster:N', sort=alt.EncodingSortField( field='fertility', op='mean', order='descending' )), y = 'mean(fertility):Q', color = alt.condition(clusterSelection, 'cluster:N', alt.value('lightgray')) ).properties( height=250, width=250 ).add_params( clusterSelection ).transform_filter( countrySelection ) #Countries detailBase = baseBars.encode( x=alt.X('country:N', sort=alt.EncodingSortField( field='fertility', op='mean', order='descending' )), y = 'mean(fertility):Q', color = 'cluster:N', opacity = alt.condition(countrySelection, alt.value(1.0), alt.value(0.35)) ).properties( height=250, width=650 ).add_params( countrySelection ).transform_filter( clusterSelection ) #clusters time series clusterTime = alt.Chart(gapminder).mark_circle().transform_filter( countrySelection ).encode( x=alt.X( 'year', scale=alt.Scale(domain=[1940, 2020]) ), y=alt.Y( 'mean(fertility):Q' ), color=alt.condition(clusterSelection, 'cluster:N', alt.value("lightgray")), size=alt.Size('mean(pop):Q'), ).add_params( clusterSelection ).properties( height=250, width=250 ) (overviewBase | detailBase) & clusterTime
Here is the report:
If I filter a cluster, it works fine:
But if I filter a country and cluster, it all turns blue (the opacity works fine):
Filtering countries without filtering clusters firsts, works fine:
I guess there is some kind of conflit when both filters are active at the same time, somehow the color binding condition is wrong, but can not figure it out how to solve it.
Any help?
Answers
-
Hi @Uderman
I believe there has been some confusion here. Your query is related to altair the Python package, for which you should go to Vega-Altair. This community is focused on the Altair RapidMiner platform.
Best,
Roland
0