PlotlyKaleido.jl is for saving Plotly.js plots in a variety of formats using Kaleido.
julia> PlotlyKaleido.ALL_FORMATS
7-element Vector{String}:
"png"
"jpeg"
"webp"
"svg"
"pdf"
"eps"
"json"
This code was originally part of PlotlyJS.jl.
using PlotlyKaleido
import PlotlyLight, EasyConfig, PlotlyJS
PlotlyKaleido.start() # start Kaleido server
p1 = PlotlyLight.Plot(EasyConfig.Config(x = rand(10)))
p2 = PlotlyJS.plot(PlotlyJS.scatter(x = rand(10)))
# PlotlyKaleido is agnostic about which package you use to make Plotly plots!
PlotlyKaleido.savefig(p1, "plot1.png")
PlotlyKaleido.savefig(p2, "plot2.png")
If needed, you can restart the server:
PlotlyKaleido.restart()
or simply kill it:
PlotlyKaleido.kill_kaleido()
To enable LaTeX (using MathJax v2) in plots, use the keyword argument mathjax
:
PlotlyKaleido.start(mathjax=true) # start Kaleido server with MathJax enabled
Many people on Windows have issues with the latest (0.2.1) version of the Kaleido library (see for example discourse, this PR's comment and this issue on the Kaleido repository).
Many people have succesfully fixed this problem on windows by downgrading the kaleido library to version 0.1.0 (see the previously mentioned issue). If you experience issues with PlotlyKaleido.start()
hanging on windows, you may want try adding Kaledido_jll@v0.1
explicitly to your project environment to fix this. You can do so by either doing:
add Kaleido_jll@v0.1
inside the REPL package enviornment, or by calling the following code in the REPL directly:
begin
import Pkg
Pkg.add(; name = "Kaleido_jll", version = "0.1")
end