Change colors of the line by different dates

Hi,

let us say I have a time series chart and i want the line to have different colors for different date ranges.

I.e., let us say my data is daily and I want a line color for Q1, another for Q2 and another after Q2. What’d be a good way to do this using plotly python?

Also I’d want for each quarter to get a different background shadow/color… is this also possible?

@dfernan In order to color a line with different colors, you should define a scatter plot of mode='lines' for each Q, and set the corresponding color. In this case your data is a list of as many traces as Qs you have.
What you call background shadow is a shape in Plotly. Here is an example of shape definition given as answer for another forum question https://community.plotly.com/t/background-shadow-for-date-ranges-under-line-chart/7965/2.

1 Like

Hey @empet. Is it possible to incorporate this with datetime x-axis (not just date). I tried your approach in my project and it worked very well keeping just the date components in x axis but as soon as I am adding time component also, the graph is showing a horizontal line.
I am trying to achieve something like this (a curved line joining two points in a vertical axis)

But with datetime formating, i am getting this

I used this for converting datetime to string (similar to your code):
“{}-{:02.0f}-{:02.0f} {:02.0f}:{:02.0f}:{:02.0f}”.format(x.year, x.month, x.day, x.hour, x.minute, x.second)