'How can I use a sequential color map for line plots using plotly graph_objects
So basically, I want to plot a bunch of line plots with different colors that follow a color map using plotly.graph_objects.Scatter. My code looks something like this
import numpy as np
from scipy.optimize import fsolve
import plotly.graph_objects as go
import plotly.express as px
def get_s(i: float, JG3: float, init_guess: float = 10) -> float:
func = lambda s: ((s-1)**(i+3)) - 1/(JG3)
roots = fsolve(func, init_guess)
return roots[0]
def get_phi(i: float, JG3: float, s_in_1: np.array, vmcsat: float) -> np.array:
s = get_s(i, JG3)
return ((s_in_1 + 1) - s)*vmcsat
vmcsat = 0.1
i = 2
jg3 = np.logspace(-4, 10, num=15)
s_in_1 = np.linspace(0, 10, 1000)
fig = go.Figure()
for ind, val in enumerate(jg3):
phi = get_phi(i, val, s_in_1, vmcsat)
fig.add_trace(go.Scatter(x = s_in_1, y = phi, \
name=r'$\mathcal{JG^3} = 10^{%d}$'% np.log10(val),\
hovertext=np.log10(val), hoverinfo='x+y+name'))
fig.update_layout(font_size=18, width=800, height=600)
fig.update_xaxes(title_text = r'$S_{in} - 1$', range=[-2, 1], type="log", dtick=1)
fig.update_yaxes(title_text = r'$\phi$',type="log", range=[-3, 0], dtick=1)
fig.show()
which outputs this figure
now I want the line colors to follow px.colors.sequential.Blues in order but px.colors.sequential.Blues returns a list of length 8 and I have no idea how to map it to a continuous value...
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
