I plot a figure using this code. After playing this cell the program became too much slow and it is very hard to zoom the picture. How can I speed up this code? (consider that this code is not completed and in the coming updates I will need for loop, so I can not replace it)
fig = go.Figure()
data=0
X=[]
Y=[]
for trial in range(len(frames_ts)):
for data in range(len(frames_ts[trial])):
new_y=original_output[trial][data];
new_x = frames_ts[trial][data]/sampling_rate;
X.append(new_x);
Y.append(new_y);
data = data 1;
fig.add_trace(go.Scatter(x = X, y =Y, mode='markers', name='Real'))
CodePudding user response:
With go.Scatter
, Plotly adds html/svg data into the document. The more data you add, the slower is going to be the rendering done by Plotly-js. More so, rendering a trace with go.Scatter(x = X, y =Y, mode='markers')
is going to be significantly slower than rendering go.Scatter(x = X, y =Y, mode='lines')
.
As far as I can see, you have options:
- Use Plotly and
go.Scatter(x = X, y =Y, mode='lines')
. - If you really need a scatter plot, use Bokeh, which is a canvas-based and it is muuuch faster at rendering (in contrast to plotly which is html-document-based).
CodePudding user response:
- given such a large data set, use
Scattergl()
instead ofScatter()
as trace type - below code shows this - after plotting interaction is ok
import numpy as np
import plotly.graph_objects as go
go.Figure(
go.Scattergl(
x=np.linspace(0, 100, 155585),
y=np.sin(np.linspace(0, 100, 155585)),
mode="markers",
name="Real",
)
)