Plotlyjs, electron, and exporting figures

plotting

#1

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


#2

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.


#3

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.


#4

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


#5

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.


#6

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

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.


#7

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


#8

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


#9

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


#10

I did

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

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

renders fine with GR in both.


#11

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


#12

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!


#13

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


#14

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 …


#15

Definitely a good person to have working with Julia.


#16

No, I mean the save function that is part of 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.