Search code examples
pythonpython-3.xaltairvega-lite

How do I change the line color in Altair's Filled Step chart?


I am working directly on the example from the docs. I changed the fill color to red and I also want to change the line color, but it stays blue no matter what I do. I tried changing fill, stroke and color to red, but the line still stays blue.

import altair as alt
from vega_datasets import data

source = data.stocks()

alt.Chart(source).mark_area(
    color="red",
    fill="red",
    interpolate='step-after',
    line=True
).encode(
    x='date',
    y='price'
).transform_filter(alt.datum.symbol == 'GOOG')

enter image description here

Am I missing something trivial?


Solution

  • Setting color='red' or stroke='red' should work, but doesn't: this is probably a bug in Vega or Vega-Lite. But you can work around it by setting the color encoding to a value:

    import altair as alt
    from vega_datasets import data
    
    source = data.stocks()
    
    alt.Chart(source).mark_area(
        fill="red",
        interpolate='step-after',
        line=True
    ).encode(
        x='date',
        y='price',
        color=alt.value('red')
    ).transform_filter(alt.datum.symbol == 'GOOG')
    

    enter image description here