How to save static svg with plotly

question

#1
julia> using Plots

julia> plotly()
Plots.PlotlyBackend()

julia> savefig(plot(1:5,1:5), "/tmp/x.svg")

produces a HTML snippet. Is there a way to get a static SVG?

Note: I know how to do this for PlotlyJS, but that does not work for Plotly.jl and I can’t use PlotlyJS.jl now because of an open issue (unrelated).

Using v0.6-rc3, latest releases.


#2

Check @piever 's PR here: https://github.com/JuliaPlots/Plots.jl/pull/751


#3

Perhaps I misunderstand, but I thought that PR was for PlotlyJS, not Plotly. The .o field is nothing for Plotly plots.


#4

No, I misunderstood. I read your question fast and thought you meant you knew how to do it directly with PlotlyJS, but not through Plots. I should have read the question properly and followed your link, sorry about the noise.
I don’t know the answer to your question - I do know that you can presently have PlotlyJS working on 0.6 if you check out this PR on Blink, though: https://github.com/JunoLab/Blink.jl/pull/88


#5

I actually don’t think there’s a way from plotly (see the description here under plotly/plotlyjs). The best you can do I guess is either to export the plot page as pdf from your browser (less than ideal, it’s been my emergency measure since #88 ) or try and get PlotlyJS to work.


#6

I understand. What are the current best practices for getting publication-quality plots in PDF (for papers) and SVG (blogging)? gr() is fast but pretty idiosyncratic, I used it here and the title overlaps with the plot, LaTeXStrings seem to be ignored, etc.


#7

One very reliable way is https://github.com/JuliaInterop/RCall.jl with ggplot2…


#8

I’m struggling with the same problem, I thought plotlyjs was a good option but it’s not completely reliable at times


#9

I’d like to challenge the notion that this is still more reliable than doing it with Plots. It’d be nice to see it demonstrated, at least. (Aesthetic taste differs, of course).


#10

What is the problem with savefig to a pdf with any of the working Plots backends? Yes if you only want the plotly backend you currently have to check out a certain branch of Blink, but that is close to merging.
EDIT: You may actually have been asking about the Plots backends. Have you tried out pgfplots()? Sorry for sounding defensive.


#11

Oh, I didn’t want to make a comparative statement! I just find ggplot2 via RCall reliable, there is a ton of documentation and it always works for me. Might be the same with Plots.jl, I don’t really know.


#12

Cool :slight_smile: I just have a feeling that we tend to still underestimate the plotting capabilities of Julia a little and immediately caught on a chance to demonstrate it in a duel :smiley:


#13

I tried the pgfplots() backend, and actually it works fine (except for the bug below). This is my new favorite from now on for high-quality plots. Thanks!

To me you did not sound defensive. At the same time, I apologize if I came across as complaining about anything related to Plots.jl, I find this a great library and appreciate the effort of everyone involved. I was just asking for help.

Incidentally, I found that the LaTeX comment character can mess up plots with pgfplots(), MWE:

using Plots
pgfplots()
p = plot(1:5, 1:5, title = "unsanitized %")
savefig(p, "/tmp/x.pdf")

Is this known, or should I report it as an issue? Could not find it. Would be happy to make a PR with some guidance for the proper entry point.

EDIT: I wonder why I can’t mark your answer as a solution.


#14

That’s an issue, I’d say.
One cool feature of pgfplots is that you can savefig the plot to a .tex file, which makes the style of the plot inherit the style of the publication when you incorporate it in a LaTeX document. That’s a pretty killer feature if you use LaTeX.


#15

Thanks. Reported the issue, will continue on Github.