Skip to content
Advertisement

Plotly: How to change line style using px.line?

I have dataframe tha tlooks similar to this:

JavaScript

I want to create line chart in plotly that will have different line style based in the column “level”.

Right now I have the line chart with the deafult line style:

JavaScript

enter image description here

I would like to control the linestyle for each level. until know I saw that the only way to do this is to add for each “level” but using add_trace as following:

JavaScript

but I keep getting this error:

ValueError: Invalid value of type ‘builtins.str’ received for the ‘x’ property of scatter Received value: ‘Hour’

JavaScript

My end goal is to control the linestyle of the lines in my charts, better if I can do thatinside the part of “px.line”

Advertisement

Answer

One way you can set different styles through variables in your dataframe is:

JavaScript

Plot

enter image description here

Complete code

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement