MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.41k stars 312 forks source link

Feature request: Provide multiple output formats to IJulia #2195

Open benz0li opened 2 years ago

benz0li commented 2 years ago

Currently, only one output format is provided: png by default; otherwise what is set by the activate! function (e.g. CairoMakie.activate!(type = "svg"), but only if there is a match with https://github.com/JuliaLang/IJulia.jl/blob/1cdaf7e5e65c1221b4a3fac86f63253bea65a0c5/src/display.jl#L19-L28.

Please provide every MIME type specified in the first level of that vector. 👉 After executing IJulia.register_mime(MIME("application/pdf")) I would like Makie.js (CairoMakie) to return both image/svg+xml and application/pdf.

This allows IJulia to use


See https://github.com/JuliaPlots/Plots.jl/issues/4288 about the same feature request for Plots.jl.

benz0li commented 2 years ago

Cross references:

jkrumbiegel commented 2 years ago

One problem is that for some plots with lots of data points, vector graphics become very large and slow. In those cases bitmaps are desirable, but even though CairoMakie uses png by default, it seems that IJulia still saves an svg for every plot and displays that because it is ranked higher.

benz0li commented 2 years ago

One problem is that for some plots with lots of data points, vector graphics become very large and slow. In those cases bitmaps are desirable,

Agreed. Execution time (Intel® Xeon® Silver 4210R CPU @ 2.40GHz) for https://lazarusa.github.io/BeautifulMakie/withTheme/theme_dark_astronauts/ [all packages installed and precompiled]:

ℹ️ JupyterLab is able to display the svg while code-server fails miserably.

benz0li commented 2 years ago

but even though CairoMakie uses png by default, it seems that IJulia still saves an svg for every plot and displays that because it is ranked higher.

I can't confirm that. You may login at https://demo.jupyter.b-data.ch with your GitHub account, Start image Julia (pubtools:latest) + code-server and execute the following as a Jupyter notebook (.ipynb)

Pkg.add("CairoMakie")
IJulia.ijulia_mime_types
import CairoMakie

x = range(0, 10, length = 100)
y = sin.(x)
CairoMakie.lines(x, y)

in JupyterLab or code-server; whatever you prefer.

If you then cat the .ipynb file in the Terminal, cells.outputs.data of the last cell contains image/png and text/plain only.
ℹ️ IJulia does not do any image conversion on its own.

SimonDanisch commented 2 years ago

Feel free to open a PR with those changes! I don't think we currently have the resources to work on this!

benz0li commented 2 years ago

The issue is now described in detail and the solution a nice to have. I currently do not have the resources to fix this either.

I will see if I can contribute something at a later date.

P.S.: Makie is great!

ffreyer commented 2 months ago

Looks like you can set type in CairoMakie.activate!() now... Can this be closed?

asinghvi17 commented 2 months ago

No, the question is asking for all possible formats to be marked showable/actually shown so Jupyter has access to png, svg and pdf output.