# Issues with PGFPlotsX / PGFPlots

**URL:** <https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083>\
**Category:** Visualization\
**Tags:** pgfplotsx\
**Created:** [December 10, 2019, 5:32am UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083 "2019-12-10T05:32:55Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [December 10, 2019, 5:32am UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/1 "2019-12-10T05:32:56Z")

</div>

I’m trying to recreate [this graph](https://imgur.com/a/z40RAFl) using PGFPlotsX but i cannot get it to render an image. I have pdf2svg, imagemagick and latex installed.

---

<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:** [December 10, 2019, 6:25am UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/2 "2019-12-10T06:25:22Z")

</div>

This is not really a Julia question, since the graph is mostly qualitative (probably an illustration from a textbook). A well-known open source tool for graphs like these is [TikZ](https://pgf-tikz.github.io/), if you otherwise use LaTeX. Otherwise, any illustration software should do.

---

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [December 10, 2019, 4:21pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/3 "2019-12-10T16:21:27Z")

</div>

I’m using PGFPlotsX in a Jupyter Notebook. Im trying to run some of the example code but it doesnt seem to work.

Example

```julia
# Example from PGFPlotsX userdocs
using PGFPlotsX
using LaTeXStrings
@pgf Axis(
    {
        height = "9cm",
        width = "9cm",
        grid = "major",
    },
    PlotInc(Expression("-x^5 - 242")),
    LegendEntry("model"),
    PlotInc(Coordinates(
        [
            (-4.77778,2027.60977),
            (-3.55556,347.84069),
            (-2.33333,22.58953),
            (-1.11111,-493.50066),
            (0.11111,46.66082),
            (1.33333,-205.56286),
            (2.55556,-341.40638),
            (3.77778,-1169.24780),
            (5.00000,-3269.56775),
        ]
    )),
    LegendEntry("estimate")
)

```

Which outputs the following

```julia
Axis(PGFPlotsX.Options(OrderedCollections.OrderedDict{Any,Any}("height" => "9cm","width" => "9cm","grid" => "major"), true), Any[Plot(false, true, PGFPlotsX.Options(OrderedCollections.OrderedDict{Any,Any}(), false), Expression(["-x^5 - 242"]), Any[]), LegendEntry(PGFPlotsX.Options(OrderedCollections.OrderedDict{Any,Any}(), false), "model", false), Plot(false, true, PGFPlotsX.Options(OrderedCollections.OrderedDict{Any,Any}(), false), Coordinates{2}(Union{Nothing, Coordinate{2}}[Coordinate{2}((-4.77778, 2027.60977), nothing, nothing, nothing, nothing), Coordinate{2}((-3.55556, 347.84069), nothing, nothing, nothing, nothing), Coordinate{2}((-2.33333, 22.58953), nothing, nothing, nothing, nothing), Coordinate{2}((-1.11111, -493.50066), nothing, nothing, nothing, nothing), Coordinate{2}((0.11111, 46.66082), nothing, nothing, nothing, nothing), Coordinate{2}((1.33333, -205.56286), nothing, nothing, nothing, nothing), Coordinate{2}((2.55556, -341.40638), nothing, nothing, nothing, nothing), Coordinate{2}((3.77778, -1169.2478), nothing, nothing, nothing, nothing), Coordinate{2}((5.0, -3269.56775), nothing, nothing, nothing, nothing)]), Any[]), LegendEntry(PGFPlotsX.Options(OrderedCollections.OrderedDict{Any,Any}(), false), "estimate", false)])

```

Are there any additional configs I need to get this to work in Jupyter?

---

<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:** [December 10, 2019, 4:29pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/4 "2019-12-10T16:29:42Z")

</div>

Did you install the external tools, eg `pdftocairo`?

[https://kristofferc.github.io/PGFPlotsX.jl/dev/#Installation-1](https://kristofferc.github.io/PGFPlotsX.jl/dev/#Installation-1)

---

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [December 10, 2019, 5:11pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/5 "2019-12-10T17:11:48Z")

</div>

yes i get the following in jupyter

```julia
;pdf2svg

Usage: pdf2svg <in file.pdf> <out file.svg> [<page no>]

```

It seems to be compiling to .tex when i run the code but its not displaying the image

---

<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:** [December 11, 2019, 7:44am UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/6 "2019-12-11T07:44:54Z")

</div>

Please open an issue at

[https://github.com/KristofferC/PGFPlotsX.jl/issues](https://github.com/KristofferC/PGFPlotsX.jl/issues)

providing

1. the version numbers for Julia and PGFPlotsX,
2. your OS details

---

<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:** [December 11, 2019, 9:27am UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/7 "2019-12-11T09:27:45Z")

</div>

What does it do if you do

```julia
pl = @pgf Axis( ... )
display(pl)

```

?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 11, 2019, 1:10pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/8 "2019-12-11T13:10:52Z")

</div>

Can you also do

```julia
ENV["JULIA_DEBUG"] = "PGFPlotsX" 
PGFPlotsX.ACTIVE_PNG_ENGINE[] = nothing
PGFPlotsX.ACTIVE_SVG_ENGINE[] = nothing
PGFPlotsX.svg_engine()
PGFPlotsX.png_engine()

```

---

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [December 11, 2019, 5:39pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/9 "2019-12-11T17:39:33Z")

</div>

I get the following

```julia
┌ Debug: svg_engine: looking for svg engine pdftocairo
└ @ PGFPlotsX /home/usr/.julia/packages/PGFPlotsX/K4i95/src/build.jl:171
┌ Debug: svg_engine: found svg engine pdftocairo, using it
└ @ PGFPlotsX /home/usr/.julia/packages/PGFPlotsX/K4i95/src/build.jl:173
┌ Debug: png_engine: looking for png engine pdftocairo
└ @ PGFPlotsX /home/usr/.julia/packages/PGFPlotsX/K4i95/src/build.jl:135
┌ Debug: png_engine: found png engine pdftocairo, using it
└ @ PGFPlotsX /home/usr/.julia/packages/PGFPlotsX/K4i95/src/build.jl:137

PNG_PDF_TO_CAIRO::PNGEngine = 1

```

---

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [December 11, 2019, 5:41pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/10 "2019-12-11T17:41:54Z")

</div>

I get the following error

```julia
! Undefined control sequence.
\sa@placebox ->\newpage \global \pdfpagewidth 
                                              =\wd \sa@box \global \pdfpageh...
l.31 \end{tikzpicture}
The latex command `lualatex jl_GZEJAc.tex` failed

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 11, 2019, 6:04pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/11 "2019-12-11T18:04:38Z")

</div>

Was that really all output when you ran all of that?

---

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [December 11, 2019, 6:09pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/12 "2019-12-11T18:09:37Z")

</div>

updated with entire output

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 11, 2019, 8:10pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/13 "2019-12-11T20:10:54Z")

</div>

Ok, so PGFPlotsX finds `pdftocairo`. If you run `p = Axis(...)` can you do `pgfsave("plot.svg", p)`? That should check if latex and `pdftocairo` works properly.

---

<div class="post-metadata">

**Author:** ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)\
**Post date:** [December 11, 2019, 10:30pm UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/14 "2019-12-11T22:30:54Z")

</div>

It returns an error

```julia
 Debug: running latex command `lualatex jl_TkDl34.tex` in dir /tmp
└ @ PGFPlotsX /home/usr/.julia/packages/PGFPlotsX/K4i95/src/build.jl:48

! Undefined control sequence.
\sa@placebox ->\newpage \global \pdfpagewidth 
                                              =\wd \sa@box \global \pdfpageh...
l.31 \end{tikzpicture}
                    

┌ Debug: LaTeX command `lualatex jl_TkDl34.tex` failed
└ @ PGFPlotsX /home/usr/.julia/packages/PGFPlotsX/K4i95/src/tikzdocument.jl:167

The latex command `lualatex jl_TkDl34.tex` failed

Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] #savepdf#71(::PGFPlotsX.LaTeXEngine, ::Array{String,1}, ::Int64, ::String, ::typeof(PGFPlotsX.savepdf), ::String, ::TikzDocument) at /home/usr/.julia/packages/PGFPlotsX/K4i95/src/tikzdocument.jl:196
 [3] #savepdf at ./none:0 [inlined]
 [4] #savesvg#72(::PGFPlotsX.LaTeXEngine, ::Array{String,1}, ::Bool, ::typeof(PGFPlotsX.savesvg), ::String, ::TikzDocument) at /home/usr/.julia/packages/PGFPlotsX/K4i95/src/tikzdocument.jl:266
 [5] #savesvg at ./none:0 [inlined]
 [6] #save#65(::Bool, ::PGFPlotsX.LaTeXEngine, ::Array{String,1}, ::Int64, ::Bool, ::typeof(PGFPlotsX.save), ::String, ::TikzDocument) at /home/usr/.julia/packages/PGFPlotsX/K4i95/src/tikzdocument.jl:83
 [7] save(::String, ::TikzDocument) at /home/usr/.julia/packages/PGFPlotsX/K4i95/src/tikzdocument.jl:72
 [8] #save#60 at /home/usr/.julia/packages/PGFPlotsX/K4i95/src/tikzpicture.jl:33 [inlined]
 [9] save at /home/usr/.julia/packages/PGFPlotsX/K4i95/src/tikzpicture.jl:33 [inlined]
 [10] #save#55 at /home/usr/.julia/packages/PGFPlotsX/K4i95/src/axislike.jl:44 [inlined]
 [11] save(::String, ::Axis) at /home/usr/.julia/packages/PGFPlotsX/K4i95/src/axislike.jl:44
 [12] top-level scope at In[40]: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:** [December 12, 2019, 8:43am UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/15 "2019-12-12T08:43:07Z")

</div>

This may be a bug in an old version of `standalone`:

[https://tex.stackexchange.com/questions/315025/lualatex-texlive-2016-standalone-undefined-control-sequence](https://tex.stackexchange.com/questions/315025/lualatex-texlive-2016-standalone-undefined-control-sequence)

How recent is your TeX suite? If possible, I would recommend a recent TeXLive, eg 2019.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 12, 2019, 9:05am UTC](https://discourse.julialang.org/t/issues-with-pgfplotsx-pgfplots/32083/16 "2019-12-12T09:05:51Z")

</div>

The next step I would do is to write the tex file

```julia
pgfsave("plots.tex", p)

```

and then manually try running `lualatex` on it. If that fails (which it likely will) then you probably have some issues with your local latex installation (like @Tamas_Papp just mentioned).
