I am trying to plot 4 different Plotly traces to one figure.
My px.Scatter dataset is very large (32,000 data points).
This figure consists of two go.Scatter traces, a px.scatter trace, and a px.line trace.
My script runs and the traces all render on the figure.
My two go.Scatter traces ALWAYS render behind the px.scatter and px.line traces.
I had a similar issue with my px.line trace also rendering behind my px.scatter plot, but putting all the relevant data into a single data frame seemed to allow the px.line trace to render infront of the px.scatter.
I have tried manually reordering the traces in everyway possible to no avail: **Example: fig.data =(fig.data[0],fig.data[1],fig.data[2]) **
Notice the grey shaded region behind the scatter plot and line plots. How can I bring this to the front
import pandas as pd
import numpy as np
import plotly.graph_objects as go
import plotly.io as pio
import plotly.express as px
pio.renderers.default='browser'
df3 = pd.read_csv('filename.csv')
fig1 = px.scatter(df3, x="height_diff", y="flow_speed",
trendline="ols",
trendline_color_override = 'crimson',
template='plotly',
color_continuous_scale='Viridis',
color=np.random.randn(32145),
title='Linear Regression, HYCOM GOFS3.1, 2010-2020, 3hourly mean height difference vs. 3hourly mean Florida Current flow speed'
)
fig1.add_traces(px.line(df3, x="hgt_roll_avg", y="flow_roll_avg",color_discrete_sequence=['black']).data)
#fig2 = px.line(df3, x="hgt_roll_avg", y="flow_roll_avg",color_discrete_sequence=['black'])
#fig3 = go.Figure(data=fig1.data + fig.data, layout = fig1.layout)
fig1.update_layout(coloraxis_showscale=False,colorscale=dict(diverging = 'Viridis'))
fig1.add_traces([
go.Scatter(
name='Upper Bound',
x=df3['hgt_roll_avg'],
y=df3['flow_roll_avg']+df3['std'],
mode='lines',
marker=dict(color="#444"),
line=dict(width=1),
showlegend=False
),
go.Scatter(
name='Lower Bound',
x=df3['hgt_roll_avg'],
y=df3['flow_roll_avg']-df3['std'],
marker=dict(color="#444"),
line=dict(width=1),
mode='lines',
fillcolor='rgba(68, 68, 68, 0.3)',
fill='tonexty',
showlegend=False
)
])
fig1.show()
If there is not a solution to this issue, is it possible to produce this plot using only go.Scatter?