# How to save static svg with plotly

**URL:** https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225
**Category:** Visualization
**Tags:** question, plots, plotlyjs
**Created:** [June 12, 2017, 1:45pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225 "2017-06-12T13:45:25Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 12, 2017, 1:45pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/1 "2017-06-12T13:45:25Z")

</div>

```julia
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](https://github.com/JuliaPlots/Plots.jl/issues/750), 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.

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [June 12, 2017, 2:06pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/2 "2017-06-12T14:06:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 12, 2017, 2:14pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/3 "2017-06-12T14:14:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [June 12, 2017, 2:43pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/4 "2017-06-12T14:43:51Z")

</div>

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](https://github.com/JunoLab/Blink.jl/pull/88)

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [June 12, 2017, 2:48pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/5 "2017-06-12T14:48:30Z")

</div>

I actually don’t think there’s a way from plotly (see the description [here](https://juliaplots.github.io/backends/) 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](https://github.com/sglyon/PlotlyJS.jl/issues/88) ) or try and get PlotlyJS to work.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 12, 2017, 7:04pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/6 "2017-06-12T19:04:51Z")

</div>

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](https://tpapp.github.io/post/ess-sampling/) and the title overlaps with the plot, `LaTeXStrings` seem to be ignored, etc.

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [June 12, 2017, 7:24pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/7 "2017-06-12T19:24:49Z")

</div>

> [@Tamas\_Papp](#):
>
> What are the current best practices for getting publication-quality plots in PDF (for papers) and SVG (blogging)?

One very reliable way is [GitHub - JuliaInterop/RCall.jl: Call R from Julia](https://github.com/JuliaInterop/RCall.jl) with ggplot2…

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [June 12, 2017, 7:32pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/8 "2017-06-12T19:32:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [June 12, 2017, 7:47pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/9 "2017-06-12T19:47:51Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [June 12, 2017, 7:50pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/10 "2017-06-12T19:50:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [June 12, 2017, 7:54pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/11 "2017-06-12T19:54:23Z")

</div>

> [@mkborregaard](#):
>
> 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).

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.

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [June 12, 2017, 8:04pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/12 "2017-06-12T20:04:32Z")

</div>

Cool 🙂 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 😃

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 13, 2017, 10:21am UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/13 "2017-06-13T10:21:07Z")

</div>

> [@mkborregaard](#):
>
> Have you tried out pgfplots()? Sorry for sounding defensive.

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:

```julia
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.

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [June 13, 2017, 11:26am UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/14 "2017-06-13T11:26:41Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 13, 2017, 1:15pm UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/15 "2017-06-13T13:15:27Z")

</div>

Thanks. Reported the issue, will continue on Github.  
[https://github.com/JuliaPlots/Plots.jl/issues/928](https://github.com/JuliaPlots/Plots.jl/issues/928)

---

<div class="post-metadata">

### Author: ![Vahid\_Hosseinzadeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vahid_hosseinzadeh/32/33293_2.png) [@Vahid\_Hosseinzadeh](https://discourse.julialang.org/u/Vahid_Hosseinzadeh)
#### Post date: [March 25, 2022, 10:09am UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/16 "2022-03-25T10:09:46Z")

</div>

I do not know if this problem is solved by now but have the same problem with Plotly when I am working on Jupyter or Pluto. However in VsCode it actually dump it as svg.

---

<div class="post-metadata">

### Author: ![senhalil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/senhalil/32/42473_2.png) [@senhalil](https://discourse.julialang.org/u/senhalil)
#### Post date: [September 6, 2022, 9:27am UTC](https://discourse.julialang.org/t/how-to-save-static-svg-with-plotly/4225/18 "2022-09-06T09:27:07Z")

</div>

> [@Vahid\_Hosseinzadeh](#):
>
> However in VsCode it actually dump it as svg.

It looks like this is a VSCode issue [Plot pane save fails for anything other than SVG · Issue #2972 · julia-vscode/julia-vscode · GitHub](https://github.com/julia-vscode/julia-vscode/issues/2972)
