ANN: PGFPlotsX


#1

ANN: PGFPlotsX

PGFPlotsX (https://github.com/KristofferC/PGFPlotsX.jl) is (yet another) plotting package that aims to provide a convenient way of using PGFPlots http://pgfplots.sourceforge.net/ (a plotting library for LaTeX) from Julia.
We (me and @Tamas_Papp ) have chosen to make the API such that the syntax written in Julia has a similar structure to the one you would write in LaTeX. PGFPlots is a mature plotting library and has tons of documentation and examples and since the structure is similar, it is quite easy to adopt example you see given in LaTeX to Julia. The advantage of doing stuff in Julia is, of course, that we can directly use our data from the analysis we run and that programming in Julia is much nicer than in LaTeX.

The original reason for creating this package was that I really wanted to use PGFPlots to generate the figures for one of my papers to keep the typesetting consistent with the rest of the paper.
I was however not at all happy with the ways I could do that from Julia, most of the things I tried (Plots.jl, PGFPlots.jl) seemed to try to abstract away the PGFPlots-backend but I wanted direct access to it to be able to use all its features. Being able to directly (but with high convenience) use PGFPlots has been one of the core guiding principles.

To list some features:

  • Support for directly using some of the types defined in popular packages, for example Colors, DataFrames, StatsBase, Contours etc (see some examples at https://kristofferc.github.io/PGFPlotsX.jl/latest/examples/juliatypes.html).
  • PGFPlotsX takes about 1.5s to load and around 1-2 seconds for the first plot to show up.
  • The generated figures are shown inline in IJulia, Juno and VSCode.
  • Figures can be exported to pdf, svg, png and also to tex to directly be included in e.g. a scientific paper.

Happy plotting!


#2

Fantastic, I will give this a try.


#3

For those unfamiliar with pgfplots (the LaTeX package), see their gallery. These are all in LaTeX, but can be easily translated to the syntax used by PGFPlotsX. Also, the collection of all the plots in their pgfplots manual is a good reference.

It is important to note that this package is not the solution to all Julia plotting woes, but is a good alternative for those who want to use their plots in papers using TeX and/or like pgfplots already.


#4

How is its performance? I really like Gadfly, but it is slow.


#5

See above:

That said, plots with a lot of data points can strain LaTeX. The default engine is LuaLaTeX though, which is better.


#6

As Tamas says, since PGFPlotsX just compiles to tex where the rendering takes place, that is usually where the bottleneck is.

While it is possible to make figures like:

(using the following code)

function julia(z, maxiter)
    c = -0.742 + 0.1im
    for n = 1:maxiter
        abs2(z) > 4 && return n-1
        z = z^2 + c
    end
    return 0
end

x = linspace(-2, 2, 250)
y = linspace(-1, 1, 250)
m = (x, y) -> julia(complex(x, y), 10000)

@pgf Axis(
    {
        width = "14cm",
        view = (0, 90),
        "colormap/hot2",
        axis_equal_image,
        point_meta_max=50,
    },
    Plot3(
        {
            surf,
            shader = "interp",
        },
        Coordinates(x, y, m.(x, y'));
    )
)

it is quite slow. I would say PGFPlots works best when you have quite simple figures.


#7

Iā€™m using this package and I LOVE it!!! You people did an amazing job! Thank you!


#8

Wow, as someone that spends way too much time plotting things in Tikz/PGFPlots, this might be a huge time saver!