Skip to content

Speed of rendering static images #1775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sursu opened this issue Sep 16, 2019 · 3 comments
Closed

Speed of rendering static images #1775

sursu opened this issue Sep 16, 2019 · 3 comments

Comments

@sursu
Copy link
Contributor

sursu commented Sep 16, 2019

I'm translating the Robust Gaussian Processes in Stan tutorial to Python.

In the process of doing that I've encountered a speed issue. Plotly is slow at plotting many (a few thousand) traces.

Reproducible example (plotting the Posterior Realizations - 3.2 in the tutorial):

Download the bag.pkl file, then run:

import pickle
import plotly.graph_objects as go

# Plot Gaussian process realizations
def plot_gp_realizations(fit, data, true):
    fig = go.Figure()
    for f in fit.extract()['f_predict']:
        fig.add_scatter(x=data['x_predict'], y=f, line_width=0.7, line_color='#8F2727', opacity=0.1)
    fig.add_scatter(x=data['x_predict'], y=true['f_total'], line_color='black', line_width=3)
    fig.add_scatter(x=data['x_predict'], y=data['y_predict'], mode='markers', marker_size=5, marker_color='#5183A1', marker_line = dict(color='white', width=1))
    fig.add_scatter(x=data['x'], y=data['y'], mode='markers', marker_size=9, marker_color='black', marker_line = dict(color='white', width=1.3))
    fig.layout.update(title='Posterior Realizations', showlegend=False, height=600)
    fig.show(renderer='svg', height=600, width=1000)


# Load bag
with open('bag.pkl', 'rb') as f:
    bag = pickle.load(f)

# Plot Gaussian process realizations
plot_gp_realizations(bag['pred_fit'], bag['data'], bag['true_realization'])

image

4000 lines over 500 data points.

Plotly takes ~30s to render the svg image.
R does it in ~2 seconds.

Now, the image in plotly is way better than the one displayed by R, but I'm wondering whether the speed can be improved further.

@nicolaskruchten
Copy link
Contributor

When rendering more than around 2000 points in line or scatter plots, we recommend using scattergl rather than scatter traces, for performance: https://plot.ly/python/webgl-vs-svg/

@sursu
Copy link
Contributor Author

sursu commented Sep 17, 2019

I've set the fig.add_scatter from the loop to fig.add_scattergl and that is only marginally faster: ~27 seconds.
I suppose it's because the traces from the loop are only over 500 points.

Apart from that, the quality of the image has decreased. And the plot is a bit messed up:

image

Apparently plotting with scattergl and scatter does not respect the order in which the traces are introduced.

@gvwilson
Copy link
Contributor

Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants