In scatter plot, create line connecting lowest y values over x

Hello. I have a dataset that creates a nice scatter plot:

However, I would like there to be a line that connects the lowest y values across time.
This is an example of what I mean:

Is there a way to do this with plotly express?

Hi @nogons welcome to the forums.

Yes, you can do that. You just have to add a trace with the minimum values:

import numpy as np
import plotly.express as px

# create data
arr = np.random.randint(0, 2000, size=(10, 30))

# create base figure
fig = px.scatter(arr)

# formatting 
fig.update_traces(
    showlegend=False, 
    marker_color='black', 
    marker_size=8
)

# add trace with minimum values
fig.add_scatter(
    x=[*range(10)], 
    y=np.min(arr, axis=1), 
    name='minumum', 
    marker_color='red', 
    marker_symbol='circle-open',
    marker_size=11
)

# layout
fig.update_layout(height=700, width=700)
fig.show()

creates:

1 Like