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

GR performance: SVG, not HTML, and use PNG for large plots #1090

Merged
merged 4 commits into from
Apr 14, 2021

Conversation

fonsp
Copy link
Owner

@fonsp fonsp commented Apr 13, 2021

Implemented:

Hide whitespace in the diff: https://github.com/fonsp/Pluto.jl/pull/1090/files?diff=split&w=1

Try it out!

julia> ]
pkg> activate --temp
pkg> add Pluto#plots-performance
julia> import Pluto; Pluto.run()

@fonsp
Copy link
Owner Author

fonsp commented Apr 13, 2021

@daschw @jheinen FYI: Pluto will now skip the HTML MIME type for outputs of type Plots.Plot{Plots.GRBackend}. I improvised a function to count the 'complexity' of a given plot, and when there are too many datapoints, SVG is also disabled, leaving PNG.

@jheinen the interactive GR mode still works, since that is not the Plots.jl type. What I was not sure about is whether you can get the Pluto-interactive GR mode as part of a Plots.Plot? If so, is there a way for Pluto to check whether that is being used for a given Plots.Plot, so that we can re-enable HTML for that plot?

@jheinen
Copy link

jheinen commented Apr 14, 2021

Right now, you can't use the GR JS backend within Plots.jl. We (only) have an idea, how this could be managed - but there's still a lot of things to do.

@fonsp
Copy link
Owner Author

fonsp commented Apr 14, 2021

Okay! @jheinen please let me know when that happens, I will need to re-enable HTML output for GR JS plots. Important is that Pluto can use a function:

prefers_html(::Plots.Plot)::Bool

to decide whether or not HTML should be enabled. Pluto-managed SVG and PNG output has significant performance benefits over SVG-inside-HTML or PNG-inside-HTML.

@fonsp fonsp added frontend Concerning the HTML editor other packages Integration with other Julia packages display & PlutoRunner & AbstractPlutoDingetjes.jl labels Apr 14, 2021
@fonsp fonsp merged commit 6492666 into main Apr 14, 2021
@fonsp fonsp deleted the plots-performance branch April 14, 2021 17:47
@pankgeorg
Copy link
Collaborator

pankgeorg commented Apr 21, 2021

#1111

The size of the surface plot in the above issue is calculated to be 201, while the SVG size is about 700MB, and it crashes the browser
An idea is to default to PNG for all surfaces or for all plots in general (and allow opt-in SVG using DisplayAs)

Another idea is to default to PNG, but respect an explicit Plots.jl option, if it exists.

@jheinen
Copy link

jheinen commented Apr 22, 2021

To which surface plot do you refer? MWE?

@pankgeorg
Copy link
Collaborator

pankgeorg commented Apr 22, 2021

To which surface plot do you refer? MWE?

From the issue I've linked: #1111

x_range = -10:0.01:10
surface(x_range, x_range, (x, y)->sin(x)+cos(y), fillalpha=0.5, color=:coolwarm)

@jheinen
Copy link

jheinen commented Apr 22, 2021

It seems that Plots doesn't use GR's software renderer to create 3d surface plots. The SVG size of the following plain GR example is about 400K.

using GR
x_range = -10:0.01:10
surface(x_range, x_range, (x, y)->sin(x)+cos(y))

Screen Shot 2021-04-22 at 10 09 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display & PlutoRunner & AbstractPlutoDingetjes.jl frontend Concerning the HTML editor other packages Integration with other Julia packages
Projects
None yet
3 participants