Issues with PGFPlotsX / PGFPlots

Iā€™m trying to recreate this graph using PGFPlotsX but i cannot get it to render an image. I have pdf2svg, imagemagick and latex installed.

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, if you otherwise use LaTeX. Otherwise, any illustration software should do.

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


# Example from PGFPlotsX userdocs
using PGFPlotsX
using LaTeXStrings
@pgf Axis(
        height = "9cm",
        width = "9cm",
        grid = "major",
    PlotInc(Expression("-x^5 - 242")),

Which outputs the following

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?

Did you install the external tools, eg pdftocairo?

1 Like

yes i get the following in jupyter


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

Please open an issue at


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

What does it do if you do

pl = @pgf Axis( ... )


Can you also do

1 Like

I get the following

ā”Œ 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


I get the following error

! 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

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

updated with entire output

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.

1 Like

It returns an error

 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

 [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(, ::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

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

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

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

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

1 Like