# Plotlyjs, electron, and exporting figures

**URL:** <https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [August 22, 2017, 4:04pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507 "2017-08-22T16:04:29Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ko56](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ko56/32/2684_2.png) [@ko56](https://discourse.julialang.org/u/ko56)\
**Post date:** [August 22, 2017, 4:04pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/1 "2017-08-22T16:04:29Z")

</div>

I am using Julia 0.6 on FreeBSD with Plots.jl and plotly() for graphics.

Is there a solution for exporting plots to pdf, say, which is less heavyweight than installing Electron? Electron does not work on FreeBSD. (I also have matplotlib, but I like the interactivity of plotly.)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 22, 2017, 7:03pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/2 "2017-08-22T19:03:23Z")

</div>

I find this is a good place for switching backends. The plotly backend just doesn’t seem to save plots very well, so I use it interactively a lot but switch to pyplot for publications. The Pgfplots backends is probably good but I never got it working since CentOS makes it difficult.

Of course, that might not be a satisfying answer but I haven’t found a better way to handle it over the last year, and Plots makes changing the backend easy enough that it’s stayed my solution.

---

<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:** [August 22, 2017, 7:26pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/3 "2017-08-22T19:26:51Z")

</div>

> [@ChrisRackauckas](#):
>
> I find this is a good place for switching backends. The plotly backend just doesn’t seem to save plots very well, so I use it interactively a lot but switch to pyplot for publications. The Pgfplots backends is probably good but I never got it working since CentOS makes it difficult.

I’m actually curious as to whether/when this is going to change: with a little more polish GR should be capable of producing publication quality plots (at least, I’m trying to use it for that, let’s see how that goes) and it should also have interactivity coming soon.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 22, 2017, 7:35pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/4 "2017-08-22T19:35:45Z")

</div>

GR is getting a brand new interactive gui too. See the JuliaCon video for details. I think it will be amazing pretty soon.

---

<div class="post-metadata">

**Author:** ![ko56](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ko56/32/2684_2.png) [@ko56](https://discourse.julialang.org/u/ko56)\
**Post date:** [August 22, 2017, 7:41pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/5 "2017-08-22T19:41:31Z")

</div>

I will check out GR. As far as PGFPlots is concerned, I tried it, but couldn’t figure out how to export to pdf, it would only produce svg.

---

<div class="post-metadata">

**Author:** ![JackDevine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackdevine/32/1048_2.png) [@JackDevine](https://discourse.julialang.org/u/JackDevine)\
**Post date:** [August 23, 2017, 6:26am UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/6 "2017-08-23T06:26:11Z")

</div>

You should be able to do this by just changing the file extension, quoting from the documentation:

```julia
p = Plots.Histogram(rand(10))
save("myfile.tex", p)
save("myfile.pdf", p)
save("myfile.svg", p)

```

Personally, I like to save as .tex so then when I compile my document, the plot will get generated by pgfplots (with all the right font sizes and so on). To me, that is the whole point of pgfplots.

---

<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:** [August 23, 2017, 8:42am UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/7 "2017-08-23T08:42:14Z")

</div>

Yes, the .tex trick from pgfplots is really nice.  
@ko56 you may need to install pdf2svg.

---

<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:** [August 23, 2017, 9:24am UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/8 "2017-08-23T09:24:25Z")

</div>

> [@piever](#):
>
> GR should be capable of producing publication quality plots

It is _almost_ there, nice `SVG` and `PDF` output, the only thing I am missing ATM is `LaTeXStrings` integration, so I have to change the labels when I use `Plots.jl`. Cf

> <https://github.com/jheinen/GR.jl/issues/43>
>
> The key thing that's stopping me using GR is that I can't pass a LaTeX string (e….g. from the LaTeXStrings.jl package) and have it rendered as an axis label or whatever. I know there's some support for Greek letters but it's not as complete as matplotlib, which will accept basically any LaTeX you give it. 
> 
> Is this something that GR will be able to do one day?

---

<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:** [August 23, 2017, 9:28am UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/9 "2017-08-23T09:28:23Z")

</div>

You can pass LaTeXStrings to gr when using it as a Plots backend.

---

<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:** [August 23, 2017, 10:22am UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/10 "2017-08-23T10:22:14Z")

</div>

I did

```julia
using Plots
using LaTeXStrings
gr()

plot(1:3, 1:3, xlab = L"\alpha", ylab = L"\beta")
savefig("/tmp/x.pdf")
savefig("/tmp/x.svg")

```

and the PDF is fine, but the in SVG the greek labels are pixelated or don’t render (depending on the viewer). OTOH

```julia
plot(1:3, 1:3, xlab = "\\alpha", ylab = "\\beta")

```

renders fine with GR in both.

---

<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:** [August 23, 2017, 10:30am UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/11 "2017-08-23T10:30:57Z")

</div>

There’s an issue with savefig for gr that Josef is looking into right now.

---

<div class="post-metadata">

**Author:** ![John\_Hearns](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_hearns/32/1685_2.png) [@John\_Hearns](https://discourse.julialang.org/u/John_Hearns)\
**Post date:** [August 23, 2017, 2:18pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/12 "2017-08-23T14:18:51Z")

</div>

Ooooh… From the GR front page: “GR is essentially based on an implementation of a Graphical Kernel System (GKS) and OpenGL” Back in 1986 no less(!) I became somewhat of an expert in GKS, in order to produce colour plots of detector uniformity and energy at CERN. This was on a Tektronix terminal - actually not strictly true. I did use real Tek terminals, which were big beasts. I was the proud owner of a Falco terminal on my desk, which would hotkey between a VT100 amber text terminal and a colour Tektronix compatible mode. Happy days.  
I did not know that GKS was still in vogue.

Keeping slightly on topic, I did take those GKS plots and turn them into (encapsulated) PDFs to send off to the special colour printer to produce the diagrams for my thesis. I guess with GR.jl this process is a breeze!

---

<div class="post-metadata">

**Author:** ![ko56](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ko56/32/2684_2.png) [@ko56](https://discourse.julialang.org/u/ko56)\
**Post date:** [August 23, 2017, 3:41pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/13 "2017-08-23T15:41:20Z")

</div>

Thanks. I think you meant savefig(p, “myfile.pdf”), right?

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [August 23, 2017, 4:19pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/14 "2017-08-23T16:19:12Z")

</div>

> [@John\_Hearns](#):
>
> I did not know that GKS was still in vogue.

Good ideas never get out of fashion. The first time i read about it was ~1997 (still studying) and after some web-searching found again.

Title page:  
2D- und 3D-Visualisierung  
mit den Graphiksystemen  
GR, GLI, IDL und AVS -  
Ein Überblick  
Dr. H. Schumacher  
M.Busch  
J.Heinen  
20.März.1996  
Forschungszentrum Jülich GmbH  
Institut für Festkörperforschung

J Heinen sounds familiar …

---

<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:** [August 23, 2017, 5:13pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/15 "2017-08-23T17:13:16Z")

</div>

Definitely a good person to have working with Julia.

---

<div class="post-metadata">

**Author:** ![JackDevine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackdevine/32/1048_2.png) [@JackDevine](https://discourse.julialang.org/u/JackDevine)\
**Post date:** [August 23, 2017, 9:21pm UTC](https://discourse.julialang.org/t/plotlyjs-electron-and-exporting-figures/5507/16 "2017-08-23T21:21:28Z")

</div>

> [@ko56](#):
>
> I think you meant savefig(p, “myfile.pdf”), right?

No, I mean the save function that is part of [PGFPlots.jl](https://github.com/sisl/PGFPlots.jl). If you want to access it from Plots.jl then you will need to write `PGFPlots.save(...)`. Also, just to be even more confusing, the order of the arguments is different between `Plots.savefig` and `PGFPlots.save`.
