# Plots.jl PGFplotsX backend is a massive boon for Julia

**URL:** <https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699>\
**Category:** Community\
**Tags:** plotting, diffeq, latex, plots, pgfplotsx\
**Created:** [May 23, 2021, 11:19pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699 "2021-05-23T23:19:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)\
**Post date:** [May 23, 2021, 11:20pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/1 "2021-05-23T23:20:00Z")

</div>

There’s a lot of talk of Makie replacing plots.jl. I get it. I’ve just started using Makie and I think it’s great. However, I’ve also just started realising the power of PGFplotsX as a plots/statsplots backend. For a start, easily creating violin plots from data for seamless integration in a LaTeX document is something I’ve been looking for for a long time. R + TikzDevice can do this but the output is much harder to tweak without lots of trial and error, since it’s a picture , not an axis. The real revelation for though was taking complex plots produced using BifurcationKit and doing the same. I really hope this is something that continues in Julia, the ability to produce a complex figure just by calling plot() and get a .tex output.

If there is a general trend towards using Makie Vs Plots for visualising the output of popular packages, it would be great to have some equivalent of TikzDevice to convert Cairo to tikz. I have no idea how difficult this would be (probably quite).

Edited first sentence, as it misrepresented @ChrisRackauckas

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 24, 2021, 5:30am UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/2 "2021-05-24T05:30:50Z")

</div>

If someone was interested enough, it would be possible to just write a tikz backend for Makie which copies the CairoMakie implementation because both use the same 2D vector graphics operations anyway that you then find in pdfs or svgs. I guess the difference is whether you have the tikz intermediary or not, which can render your plot with different fonts in your latex document. But if you do change fonts from whatever makie used to calculate metrics you could end up with overlapping things that don’t look quite right. I’ve never used tikz though, so I might misunderstand what you’re really looking for here

---

<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:** [May 24, 2021, 8:48am UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/3 "2021-05-24T08:48:36Z")

</div>

I would also tend to imagine that changing the font after the fact could be problematic.

A bit off-topic, but I wonder if it wouldn’t be easier to support some sort of “editable format”, so that it’s easy to redraw the plot with a different theme. Maybe just saving with a serializer that also records the package versions (like [JLSO](https://github.com/invenia/JLSO.jl)) could already get us halfway there.

---

<div class="post-metadata">

**Author:** ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)\
**Post date:** [May 24, 2021, 10:13am UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/4 "2021-05-24T10:13:25Z")

</div>

The nice thing about a PGFplots/PGFplotsX backend is that the plot is still saved as a plot. So it’s straight forward to mess around with the theme in a LaTeX editor afterwards (if need be).

---

<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:** [May 24, 2021, 12:23pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/5 "2021-05-24T12:23:34Z")

</div>

> [@EvoArt](#):
>
> it would be great to have some equivalent of TikzDevice to convert Cairo to tikz

As a contributor to PGFPlotsX, I am always happy to hear that people find it useful.

However, note that `tikz` code uses LaTeX for rendering, and as such it is one or two orders of magnitude slower than almost everything else. The benefit is of course the really polished look and LaTeX integration, but the cost is considerable and may make this less than ideal for a general backend.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [May 24, 2021, 12:34pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/6 "2021-05-24T12:34:53Z")

</div>

> [@EvoArt](#):
>
> I know @ChrisRackauckas has mentioned several times a desire to move diffeq plotting recipes over to Makie

I think the dream would be (and is?) to have full RecipiesBase support in Makie.  
I know there is partial support right now.

That way DiffEq etc just needs to contine to support RecipiesBase.  
and Plots.jl (with all its backends) as well as Makie would just work with it.  
I know there was talk a while ago of adding RecipiesBase support to Vegalite.jl also

---

<div class="post-metadata">

**Author:** ![willtebbutt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willtebbutt/32/6790_2.png) [@willtebbutt](https://discourse.julialang.org/u/willtebbutt)\
**Post date:** [May 24, 2021, 12:39pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/7 "2021-05-24T12:39:30Z")

</div>

Just wanted to add that I also find the PGFPlotsX backend for Plots incredibly helpful – as has been said, it’s necessarily slower than other backends, but I’ve found it invaluable when producing publication-ready figures directly from my Julia code. It would be a shame for the community to lose that functionality.

Regarding performance, I’ll often switch between backends depending upon what I’m doing – so I’ll e.g. use GR as I’m developing, but when it comes to writing up, I’ll switch to the backend PGFPlotsX backend.

---

<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:** [May 24, 2021, 1:34pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/8 "2021-05-24T13:34:54Z")

</div>

I never worked with tikz, is there a good overview of the process of rendering via LaTeX available (afair LaTeX → TeX doesn’t do rendering but outputs display lists like dvi)?

---

<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:** [May 24, 2021, 1:49pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/9 "2021-05-24T13:49:44Z")

</div>

Pgfplots uses Tikz/pgf, which first expands graphics to a set of primitives known as the “basic layer”, then that is expanded via a “system layer” (for PDF etc). Parts IX and X of its [manual](http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf) document these.

Since LaTeX wasn’t really designed for this kind of computation but is otherwise Turing-complete, it emulates decent floating point (`pgfmath`) and a lot other basic stuff… in TeX (of course more recent engines like LuaTeX get shortcuts and are faster).

Since Tikz is so closely tied to TeX and kind of the whole point is that you can escape to TeX any time, it is conceptually difficult to do this any other way.

---

<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:** [May 24, 2021, 2:02pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/10 "2021-05-24T14:02:24Z")

</div>

> [@oxinabox](#):
>
> I think the dream would be (and is?) to have full RecipiesBase support in Makie.  
> I know there is partial support right now.
> 
> That way DiffEq etc just needs to contine to support RecipiesBase.  
> and Plots.jl (with all its backends) as well as Makie would just work with it.  
> I know there was talk a while ago of adding RecipiesBase support to Vegalite.jl also

Exactly. Let me make it clear that I won’t be deprecating or abandoning Plots.jl recipe support for the SciML ecosystem. Rather, I want to make sure it all works with Makie, and I myself want to then transition to Makie. The code won’t be deleted, it will be maintained, but likely it won’t grow much past that point unless it’s able to be written in a way where the same recipe pieces work with both systems. I’d hope other systems support such recipes to, but it’s not that easy.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [May 24, 2021, 3:49pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/11 "2021-05-24T15:49:57Z")

</div>

> [@jules](#):
>
> But if you do change fonts from whatever makie used to calculate metrics you could end up with overlapping things that don’t look quite right.

> [@piever](#):
>
> I would also tend to imagine that changing the font after the fact could be problematic.

Actually, changing fonts (both sizes and typeface) in pgfplots works incredibly well. pgfplots is a high-level description of the plot, most of the time you write stuff like ‘put this below left of that, make the lines really thick, and put extra spacing around it,’ etc. The lower level layout engine (and TeX itself) will make it look right.

You can do much more dramatic changes than fonts, even change the aspect ratio of your plot after the fact, and it still comes out right.

Pgfplots and tikz are real TeX formats, I cannot overstate how well it works with LaTeX documents.

On the flip side, this makes it non-trivial to use pgfplots as a ‘backend’, you rather need something like a ‘translator’ that re-creates your plot in the pgfplots style. Alternatively, you use the tikz or pgf commands directly to ‘dumbly’ export the graphics commands on a lower level, but then lose some of the flexibility and adaptability of the higher level description.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [May 24, 2021, 5:32pm UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/12 "2021-05-24T17:32:05Z")

</div>

Continuing on DNF’s comment, there are two concrete examples of software interaction with TikZ/Pgfplots (that I know of at least) :

- [Inkscape’s TikZ export](https://tex.stackexchange.com/questions/151232/exporting-from-inkscape-to-latex-via-tikz) which is as DNF said relatively _dumb_ as it is based on very low level objects.
- The [`matlab2tikz`](https://github.com/matlab2tikz/matlab2tikz) tool for matlab (and it’s python counterpart [`tikzplotlib`](https://pypi.org/project/tikzplotlib/)) which I personally use a lot when I’m on matlab and which are much more high level as they mostly work with pgfplots `axes`.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [May 26, 2021, 7:36am UTC](https://discourse.julialang.org/t/plots-jl-pgfplotsx-backend-is-a-massive-boon-for-julia/61699/13 "2021-05-26T07:36:39Z")

</div>

we are actually half way there. Last VizCon [RecipesPipeline](https://github.com/JuliaPlots/RecipesPipeline.jl) was split from Plots.jl and there was a time when [MakieRecipes](https://github.com/JuliaPlots/MakieRecipes.jl) consumed DiffEq-recipes.  
But Makie is evolving fast and so that got left behind. One day it will catch up.
