Hello,
I’m very new to plotly and I’m trying to refresh the data in shown plot.
In the docs I’ve found the update_traces function which looked promising to me. When I run the following example code the plot is showing in the browser with the first data. But afterwards the plot is not changed anymore.
import time
import plotly.graph_objects as go
# Fist Data
r1 = [1, 2, 3, 4, 5]
theta1 = [0, 45, 90, 135, 180]
print("Creating and showing Plot with first data")
fig = go.Figure()
fig.add_trace(go.Scatterpolar(r=r1, theta=theta1, mode='markers', marker=dict(size=20, color="MediumPurple")))
fig.show()
time.sleep(3)
print("Update to second data")
r2 = [2, 3, 4, 5, 6]
theta2 = [0, 30, 60, 90, 120]
fig.update_traces(r=r2, theta=theta2, marker=dict(size=10, color="LightSeaGreen"))
time.sleep(3)
print("Update to third data")
r3 = [4, 5, 6]
theta3 = [90, 135, 170]
fig.update_traces(r=r3, theta=theta3, marker=dict(size=20, color="MediumPurple"))
When I debug the script and take a look into the fig after I did the update_traces, I can see that the data for r and theta has changed. So the function does what it is supposed to do, unfortunately I can only see changes if i run fig.show() after each update_traces.
Is there a way to update the data in one plot without opening a new plot in the browser each time?
Big thanks in advance.