ANN: static image export in PlotlyBase.jl

Hi all!

I’m excited to announce version 0.4 of PlotlyBase.jl which adds static image export that does not require Blink.jl, or any external web process! This can easily run on remote machines without a display.

We have integrated with plotly’s new C++ based image exporter kaleido to provide a fast and seamless experience for Plotly users in Julia.

This new functionality makes the ORCA.jl package obsolete and no longer required for exporting figures to files.

To use it make sure you have the latest PlotlyBase (or PlotlyJS, which uses PlotlyBase under the hood) installed on your system and then do:

using PlotlyBase  # or using PlotlyJS

# construct a plot -- this is just random lines
p = Plot(rand(10, 4))   # or `plot(...)` if you used PlotlyJS

savefig(p, "myfile.png")
savefig(p, "myfile.pdf")
savefig(p, "myfile.jpg")

# other file formats... 

Please take it for a spin let us know how it works!

14 Likes

Hi Spencer,

This is exciting. I remember speaking with you about the problems with Plotly depending on Electron many years ago. So thanks for doing this (and thanks to the Plotly folks as well)

It may be worth making a separate package out of this, since I imagine other packages might want to use this.

Also, I see that the plotly folks provide pre-compiled binaries on linux64/mac/win64, which satisfies most of our users. However, I do hope we can get BinaryBuilder to build for all our other platforms.

1 Like

That would be great!

I know the plotly team has been working towards more operating system coverage (just released win32 today). I bet they’d love any help the BinaryBuilder julia community can provide.

Also, PlotlyBase has very light dependencies. Only JSON, LatexStrings, Requires, and DocStringExtensions – is this light enough to be that a separate package you mentioned? Or were you specifically thinking Kaledio.jl?

PlotlyJS.jl is the one that imports this and layers in the Electron stuff.

Yeah, I was thinking of a potential Kaledio.jl. But I’m being very speculative, so take it with a grain of salt.

For me it is in both cases (“PlotlyBase” & “PlotlyJS”, v0.14.0) a capital “P” for the Plot-command.
“savefig” does not work for me.
I need to add the module name to the method: PlotlyBase.savefig() or PlotlyJS.savefig()
Do I miss something?
Here is my example:

println("Hello, World!")
using PlotlyBase
# using PlotlyJS
p_ = Plot(sin, -2pi, pi, label="sine function")
PlotlyJS.savefig(p_, "/media/data/data/julia/scripts/new_plot.pdf")
PlotlyBase.savefig(p_, "/media/data/data/julia/scripts/PlotlyBase_plot.pdf")
println("End!")

Hi @ellocco

can you show the output of running that script and let me know which operating system you are using ?

Thank you

Hi @sglyon,

it is some kind of voodoo. It seems a reboot of the machine cured the issue
with “savefig”.
I am working under Ubuntu 20.04.
Also the issue with a small “p” for “PlotlyJS” disappeared.
Both seem to be case-insensitive.

Regards,

Stefan

Thank you for nice update of the package.
I tried to control the size of saved figure but it worked for me only when I saved it as html.

using PlotlyBase
data = scatter(;y=rand(10))    
layout = Layout(;width  = 480, height = 480)

pp = Plot(data, layout)

savefig(pp, "test.html")
savefig(pp, "test.pdf")

Here is screenshot, html on the left-hand side, pdf on the right-hand side.

Hmm, I’m surpised by this. can you post the output?

I put the output to my previous post.