Hi. I want to update the data points in a 3D scatter plot fast while my python script runs. But I can’t get the update to work. I thought I knew how to do it Graph Objects, but then was advised online that “You should be using Express”.
So…I’m trying but it’s not working. Can anyone help?
Here’s my sample code:
import plotly.express as px
import time
# this top part is from docs: plotly express 3d scatter example
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color='petal_width', symbol='species')
fig.update_layout(template="plotly_dark")
fig.show()
# now update the plot in real time ?
for i in range(1000):
fig.data[0].x, fig.data[0].y = fig.data[0].y, fig.data[0].x # simple data operation: flip x & y
## Ok that alone had no effect. So...maybe push change to the plot?
fig.update_layout(uirevision='constant') # NO EFFECT
fig.update_layout(uirevision='constant', data=fig.data) ## Error: No 'data' keyword
fig.update_traces(data=fig.data) ## Error: no 'data' keyword
fig.data.update( dict(mode='markers') ) # Error: No .update on .data
time.sleep(0.05) # 50 miliseconds
What am I missing? Thanks very much!.
Caveats:
- Just an Express solution, if you please. I notice that answers on her often mandate switching to some other flavor of Plotly. I’ve already switched once now! (I did get updates working in Jupyter – by going back to Graph Objects! – but would rather not have to switch the rest of my stuff over to Jupyter.)
- I don’t want an “animation”, as in storing values as they run and then later plotting them; I want the plot to be changing in real time as the data changes.