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

# 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

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?

https://kristofferc.github.io/PGFPlotsX.jl/dev/#Installation-1

1 Like

yes i get the following in jupyter

;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

Please open an issue at

providing

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

What does it do if you do

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

?

Can you also do

ENV["JULIA_DEBUG"] = "PGFPlotsX" 
PGFPlotsX.ACTIVE_PNG_ENGINE[] = nothing
PGFPlotsX.ACTIVE_SVG_ENGINE[] = nothing
PGFPlotsX.svg_engine()
PGFPlotsX.png_engine()
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

PNG_PDF_TO_CAIRO::PNGEngine = 1

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

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

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