Lines+markers mode with Express

#1

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?

#2

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.py, 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 plotly.py for version 4.

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

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

We also have plans to improve this process of updating traces in the figure returned by a px function. https://github.com/plotly/plotly.py/issues/1484.

Hope that helps!
-Jon

3 Likes
#3

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

#4

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

#5

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

fig = (px.scatter(...)
         .update_traces(mode='lines+markers'))

See the docstring for fig.update_traces for more info.
-Jon