Add marker over scatter chart plotly

I want to add a point to a plotly scatter plot to highlight specific value.

One of the ways to do it from what I have found is the following. But the issue is that new trace is placed under the main scatter chart. Is there any way to set the order so the "level" is always on top?

import plotly.express as px
import numpy as np
import pandas as pd
from plotly import graph_objects as go

data = pd.DataFrame(np.random.normal(0, 1, (5000, 2)), columns=["x", "y"])

fig = px.scatter(data, x= "x", y="y")

fig.add_trace(
            go.Scatter(
                x=[data.iloc[10, 0]],
                y=[data.iloc[10, 1]],
                mode="markers",
                marker=dict(
                    color="red",
                    size=10,
                ),
                name="level"
            )
)

Solution 1:

It's a subtle issue with first trace being created as scattergl. Below recreates figure where first trace is modified to be scatter

import plotly.express as px
import numpy as np
import pandas as pd
from plotly import graph_objects as go

data = pd.DataFrame(np.random.normal(0, 1, (5000, 2)), columns=["x", "y"])

fig = px.scatter(data, x= "x", y="y")

fig.add_trace(
            go.Scatter(
                x=[data.iloc[10, 0]],
                y=[data.iloc[10, 1]],
                mode="markers",
                marker=dict(
                    color="red",
                    size=10,
                ),
                name="level"
            )
)

d = fig.to_dict()
d["data"][0]["type"] = "scatter"

go.Figure(d)

enter image description here