I am very new to plotly and I have spent a lot of time searching for a solution to my hopefully simple problem.
I want to fill the area between two lines using a continuous color map. In the example below, I have two lists for the low and high temperature limits, and want to fill between the two limits with a continuous colormap instead of just one solid color, using the red color to represent the highest temperature (ie 94) and blue for the lowest temperature (32). Any suggestions/comments are much appreciated.
import plotly.graph_objects as go
x = [1, 2, 3, 4, 5, 6, 7]
lowT = [35, 32, 41, 70, 79, 60, 38]
hiT = [48, 51, 48, 82, 94, 77, 51]
fig=go.Figure()
fig.add_trace(go.Scatter(x=x, y=hiT, mode=โlinesโ))
fig.add_trace(go.Scatter(x=x, y=lowT, fill=โtonextyโ, mode=โlinesโ))
fig.show()
Unfortunately I donโt think that this is possible. It might be possible to use a surface plot with a color gradient and add the lineplot as trace. This is going to be quite some work.
Abother thing you might do is add a scatterplot to โfillโ the area between the two lines in a discrete manner.
Thank you so much for your response. This explains why I could not see anything relevant in my searches.
Yes, your suggestion of having discrete fills is a good idea. Alternatively, I am also thinking that I may be able to plot a rectangle and see if I can fill it with a continuous color map, and then use scatter plots to draw the two lines on top of the rectangle. If this can be done, I can then fill the upper line to the upper edge with white and the lower line to the x axis with white, leaving the color map in the desired band between the two lines displayed. Some quick searches donโt even show this is promising though. I can use add_shape or hrect etc to draw the rectangle, but filling it with a colormap still seems difficult. I will keep trying and will post my codes if I can get it to work.
The problem still ist that the colors are set to an absolute value, so that around x=400 almost all the surface is red- you might want the colors relative between the min and max temperature lines.
Hi @AIMPED, this is fine, not a big deal. it is already much better than what I can do. My problem now is to put this in a subplot and also create frames so that I can do animation. Not sure if plotly express figure can be easily added to the graph_object Frame, and plot it inside one of the subplots. I will spend some time myself to play with this. Thanks again for your big help.