Lines+markers mode with Express


First thanks for Plotly Express. Great concept especially for us to introduce chemical engineering students (thus no dev background) to modern tools like JupyterLab for data exploration and analysis.

In one of our demo notebook we display recorded sensor data with scatter and mode=‘lines+markers’. After looking at the reference documentation I fail to see how to reproduce only within Express. Is there a way?


Hi @cfoisy,

Thanks for the kind words on plotly express. Glad you’re enjoying it and that you see it as something that will be useful to pick up for your engineering students!

Unlike, plotly express separates scatter and line into two separate functions so that the compatible options are clearer in the API. So I think the plan is that eventually you’ll make this kind of plot as two separate px calls (one for px.line and one for px.scatter), and then overlay them into a single figure. But, we don’t have the overlay operation implemented yet so at the moment you can’t easily combine the results of multiple px calls. This is something we plan to address before merging plotly express into for version 4.

In the meantime, you can take advantage of the fact that the figures returned by plotly express are figures that can be modified before being displayed. So you could do something like

fig = px.scatter(df, ...)[0].update(mode='markers+lines')

We also have plans to improve this process of updating traces in the figure returned by a px function.

Hope that helps!


Excellent news. Looking forward to test drive newer versions as they come online.


What would you recommend as the cleanest way to apply the same update to all lines in a plot (pending future updates)? Thanks!


In version 3.9+ you can now update all traces in a figure using the update_traces method.

fig = (px.scatter(...)

See the docstring for fig.update_traces for more info.