Ragnar Lothbrok
Ragnar Lothbrok

Reputation: 1135

Altair: How to Change Color of Line in Line Chart?

I have some time series data. I'm comparing 2 different series (predictions vs actual for a machine learning model). I have a line chart with both lines, but I can't figure out how to change the color of the lines, as all examples I see rely on organizing the data in a completely different way.

This is what my code looks like.

source = df

line1 = alt.Chart(source).mark_line().encode(
    x='Date', 
    y='y_preds'
)

line2 = alt.Chart(source).mark_line().encode(
    x='Date', 
    y='y_actual'
)

line1 + line2

How could I color one of the lines red without reorganizing all the data?

Upvotes: 4

Views: 5554

Answers (1)

RAVI KUMAR
RAVI KUMAR

Reputation: 426

Try this:

alt.Chart(df).mark_line().encode(
  x='x',
  y='y',
  color=alt.value("#FFAA00")
)

Upvotes: 8

Related Questions