Skip to content
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

Python interactive window drops fps when creating many plots - SVG rendering is slow #3279

Closed
janosh opened this issue Jul 10, 2019 · 13 comments
Assignees

Comments

@janosh
Copy link
Contributor

janosh commented Jul 10, 2019

Not sure how hard it is to do anything about this but I noticed that if the Python interactive window contains lots of plots already (above maybe 30), adding new ones brings the frame rate down quite significantly. Above around 60 plots, it's at less than 1 fps and makes all of VS Code become unresponsive. Once the plots are done, VS Code (including the interactive window) returns to normal.

python-interactive-many-plots-low-fps

Here's some example code to reproduce the issue.

#%%
import matplotlib.pyplot as plt
import numpy as np

for i in range(100):
    plt.plot()
    N = 50
    x = np.random.rand(N)
    y = np.random.rand(N)
    colors = np.random.rand(N)
    area = (30 * np.random.rand(N)) ** 2  # 0 to 15 point radii
    plt.title(f"plot #{i + 1}")
    plt.scatter(x, y, s=area, c=colors, alpha=0.5)
    plt.show()
@kbc8894
Copy link

kbc8894 commented Jul 11, 2019

after latest update I have same problem. please fix it!

@rchiodo
Copy link
Contributor

rchiodo commented Jul 11, 2019

Rendering to png instead of svg might speed this up.

Try adding this cell first:

%config InlineBackend.figure_format = 'png'

@rchiodo
Copy link
Contributor

rchiodo commented Jul 11, 2019

Note, that change eliminates the ability to expand the plots later.

@rchiodo
Copy link
Contributor

rchiodo commented Jul 11, 2019

Yeah that makes it a lot faster for me.

In our insider's build there's a way to do this automatically. Turn this setting off:
image

The problem is the web page we load is much slower displaying SVGs versus PNGs.

@rchiodo rchiodo changed the title Python interactive window drops fps when creating many plots Python interactive window drops fps when creating many plots - SVG rendering is slow Jul 11, 2019
@janosh
Copy link
Contributor Author

janosh commented Jul 11, 2019

I'd really like to keep the ability to zoom into plots. Not sure if this was already considered but if the number of rendered elements are a problem, I believe <canvas> generally offers much better performance than SVGs. I remember reading the former scales as O(resolution^-1) whereas the latter scales with O(# of elements^-1).

@greazer
Copy link
Member

greazer commented Jul 11, 2019

Possible solution - Generate PNGs along with the SVG, but only display the PNG in the history window. When the plot viewer opens, use the SVG.

@kbc8894
Copy link

kbc8894 commented Jul 12, 2019

@rchiodo thanks! It works!

@rchiodo
Copy link
Contributor

rchiodo commented Jul 29, 2019

@DavidKutu my fix for #3233 should fix this too.

@DonJayamanne
Copy link
Contributor

@rchiodo isn't virtualizing an option?

@rchiodo
Copy link
Contributor

rchiodo commented Jul 29, 2019

@DonJayamanne yes we want to do that too. Something like this looks promising:
https://github.com/twobin/react-lazyload

However, SVG is a lot slower than PNG. We can fix jupyter to generate both.

@rchiodo rchiodo closed this as completed Aug 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 14, 2019
@microsoft microsoft unlocked this conversation Nov 14, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@ParteekSJ
Copy link

Possible solution - Generate PNGs along with the SVG, but only display the PNG in the history window. When the plot viewer opens, use the SVG.

How do I do that?

@janosh
Copy link
Contributor Author

janosh commented Apr 21, 2021

@ParteekSJ Nothing you have to do. This is something the Jupyter extension now does internally.

@ParteekSJ
Copy link

@ParteekSJ nothing you have to do. This is something the Jupyter extension now does internally.

Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants