How do I keep area coloring consistent in Altair facet charts?

  altair, python

I want to keep my shaded areas transparent enough to see the grid underneath. All three of the facets end up different shades of gray. I want them to all look like the first one. Sample:

import altair as alt
from vega_datasets import data

source = data.cars()
source['Start'] = 100
source['Middle'] = 175
source['End'] = 250

cars = alt.Chart(source).mark_circle(size=100).encode(
    x=alt.X("Horsepower:Q"),
    y=alt.Y("Miles_per_Gallon:Q"),
    color=alt.Color('Weight_in_lbs:Q'))

area1 = alt.Chart(source).mark_rect(color='#696969',opacity=0.005).encode(
    x=alt.X('Start'), 
    x2='Middle', 
    y=alt.value(0), 
    y2=alt.value(300))

area2 = alt.Chart(source).mark_rect(color='#696969',opacity=0.01).encode(
    x=alt.X('Middle'),
    x2='End',
    y=alt.value(0), 
    y2=alt.value(300))
  
(area1+area2+cars).properties(height=300, width=300
).facet(alt.Column('Origin:N'))

Output:
enter image description here

Source: Python Questions

LEAVE A COMMENT