2022-11-14T23:00:00Z
It’s been a bit since I’m training on plotly hardly but I still don’t understand some concepts.
The context :
I have a Matrix indexed by date_time, on the scatterGL i scatter lines depending on the input of how many lines i want without a problem. As I want to add an input wich is color and x_axis range I struggle to make the graphic take the color input. To be more specific I fail to understand how to give the graph example x1 = color_input and x2 = color_input2
Here you’ll find the codes the first one plot without any input but the matrix and the second how I’m trying to add the color input. In this case a rgba value that is red and yellow, and I’m trying to use figure.update_traces(selector=color_curve) without success.
def plot_graph(MATRIX, x_text, y):
fig = go.Figure()
for i in MATRIX:
fig.add_trace(go.Scattergl(x=MATRIX[f'{i}'], y=y, name=i, textposition='top right', mode='lines+markers'))
fig.add_trace(
go.Scattergl(x=x_text, y=y, mode='text', name="Comments", text=x_text,
textfont=dict(size=10, color='#000000'),
textposition='top right', xaxis='x1'))
fig.update_yaxes(minor_ticks="inside")
fig.update_xaxes(minor_ticks="inside")
for i in range(len(MATRIX)):
if i == 0:
fig.update_layout(
xaxis=dict(gridcolor='#C5C5C5', nticks=10),
yaxis=dict(gridcolor='#C5C5C5', nticks=10, autorange="reversed"))
elif i == 1:
fig.update_layout(xaxis2=dict(overlaying='x',
side="top", position=0.985,
showgrid=False))
elif i == 2:
fig.update_layout(xaxis3=dict(overlaying='x',
side="top", position=0.97,
showgrid=False))
elif i == 3:
fig.update_layout(xaxis4=dict(overlaying='x',
side="bottom", position=0.035,
showgrid=False))
elif i == 4:
fig.update_layout(xaxis5=dict(overlaying='x',
side="bottom", position=0.020,
showgrid=False))
elif i == 5:
fig.update_layout(xaxis6=dict(overlaying='x',
side="bottom", position=0.005,
showgrid=False))
fig.update_layout(legend=dict(orientation="h", yanchor="bottom", y=1.04, xanchor="right", x=1),
margin=dict(l=0, r=0, t=150, b=0), xaxis=dict(side='top'))
fig.update_layout(autosize=False, width=600, height=1200, plot_bgcolor="#FFFFFF")
return fig.show()
def plot_graph_setting(MATRIX, y, x_text, border, color):
figure = go.Figure()
mnemonics = list(MATRIX)[0:6]
y = y
borders.update(border)
color_curve.update(color)
j = 1
for key in mnemonics:
figure.add_trace(go.Scattergl(x=MATRIX[key], y=y, mode='lines+markers', name=key, textposition='top right'
, xaxis='x' + str(j)))
j += 1
figure.add_trace(
go.Scattergl(x=x_text, y=y, mode='text', name="Comments", text=x_text,
textfont=dict(size=18, color='#000000'),
textposition='top right', xaxis='x1'))
figure.update_yaxes(minor_ticks="inside")
figure.update_xaxes(minor_ticks="inside")
figure.update_traces(selector=color_curve)
for i in range(len(mnemonics)):
if i == 0:
figure.update_layout(
xaxis=dict(tickfont=dict(color=color_curve[mnemonics[i]][0]), range=borders[mnemonics[i]],
gridcolor='#C5C5C5', nticks=10),
yaxis=dict(gridcolor='#C5C5C5', nticks=10, autorange="reversed"))
elif i == 1:
figure.update_layout(xaxis2=dict(tickfont=dict(color=color_curve[mnemonics[i]][0]), overlaying='x',
side="top", position=0.985, range=borders[mnemonics[i]], showgrid=False))
elif i == 2:
figure.update_layout(xaxis3=dict(tickfont=dict(color=color_curve[mnemonics[i]][0]), overlaying='x',
side="top", position=0.97, range=borders[mnemonics[i]], showgrid=False))
elif i == 3:
figure.update_layout(xaxis4=dict(tickfont=dict(color=color_curve[mnemonics[i]][0]), overlaying='x',
side="bottom", position=0.035, range=borders[mnemonics[i]],
showgrid=False))
elif i == 4:
figure.update_layout(xaxis5=dict(tickfont=dict(color=color_curve[mnemonics[i]][0]), overlaying='x',
side="bottom", position=0.020, range=borders[mnemonics[i]],
showgrid=False))
elif i == 5:
figure.update_layout(xaxis6=dict(tickfont=dict(color=color_curve[mnemonics[i]][0]), overlaying='x',
side="bottom", position=0.005, range=borders[mnemonics[i]],
showgrid=False))
figure.update_layout(legend=dict(orientation="h", yanchor="bottom", y=1.04, xanchor="right", x=1),
margin=dict(l=0, r=0, t=150, b=0), xaxis=dict(side='top'))
figure.update_layout(autosize=False, height=1200, width=600, plot_bgcolor="#FFFFFF")
return figure.show()
Thanks everyone for the time and the attention.