Question about PGFPlotsX.jl

What’s wrong with this, I have installed LaTeX in my Mac M1.

julia> using PGFPlotsX

julia> pgfplotsx()
Plots.PGFPlotsXBackend()

julia> surface(range(-3, 3, length = 30), range(-3, 3, length = 30),
              (x, y) -> exp(-x^2 - y^2),
              label = "",
              colormap_name = "viridis",
              extra_kwargs = :subplot)
ERROR: No LaTeX installation found, figures will not be generated. Make sure either pdflatex, xelatex or lualatex are installed and that the PATH variable is correctly set.
Stacktrace:
  [1] latexengine()
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/pUwhF/src/build.jl:19
  [2] _show(io::Base64.Base64EncodePipe, mime::MIME{Symbol("image/png")}, plt::Plots.Plot{Plots.PGFPlotsXBackend})
    @ Plots ~/.julia/packages/Plots/Xv2qA/src/backends/pgfplotsx.jl:1500
  [3] show(io::Base64.Base64EncodePipe, m::MIME{Symbol("image/png")}, plt::Plots.Plot{Plots.PGFPlotsXBackend})
    @ Plots ~/.julia/packages/Plots/Xv2qA/src/output.jl:214
  [4] base64encode(::Function, ::MIME{Symbol("image/png")}, ::Vararg{Any}; context::Nothing)
    @ Base64 /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Base64/src/encode.jl:209
  [5] _binstringmime
    @ /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Base64/src/Base64.jl:46 [inlined]
  [6] stringmime(m::MIME{Symbol("image/png")}, x::Plots.Plot{Plots.PGFPlotsXBackend}; context::Nothing)
    @ Base64 /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Base64/src/Base64.jl:43
  [7] stringmime
    @ /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Base64/src/Base64.jl:43 [inlined]
  [8] display(d::VSCodeServer.InlineDisplay, m::MIME{Symbol("image/png")}, x::Plots.Plot{Plots.PGFPlotsXBackend})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/display.jl:57
  [9] display(d::VSCodeServer.InlineDisplay, mime::String, x::Any)
    @ Base.Multimedia ./multimedia.jl:216
 [10] display(d::VSCodeServer.InlineDisplay, x::Plots.Plot{Plots.PGFPlotsXBackend})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/display.jl:165
 [11] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
 [12] #invokelatest#2
    @ ./essentials.jl:716 [inlined]
 [13] invokelatest
    @ ./essentials.jl:714 [inlined]
 [14] (::VSCodeServer.var"#65#69"{Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:176
 [15] withpath(f::VSCodeServer.var"#65#69"{Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/repl.jl:184
 [16] (::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:153
 [17] hideprompt(f::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/repl.jl:36
 [18] (::VSCodeServer.var"#63#67"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:124
 [19] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:511
 [20] with_logger
    @ ./logging.jl:623 [inlined]
 [21] (::VSCodeServer.var"#62#66"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:201
 [22] #invokelatest#2
    @ ./essentials.jl:716 [inlined]
 [23] invokelatest(::Any)
    @ Base ./essentials.jl:714
 [24] macro expansion
    @ ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
 [25] (::VSCodeServer.var"#60#61")()
    @ VSCodeServer ./task.jl:429

Hi,

I’m trying to plot using Plots.jl with PGFPlotsX.jl as a backend in Visual Studio.
I have this error message:
No LaTeX installation found, figures will not be generated. Make sure either pdflatex or lualatex are installed and that the PATH variable is correctly set.

How do I set the PATH?

I do have latex installed. Furthermore, I can plot using PGFPlotsX using Juno (Atom) and using Jupyter Notebooks. It is only in Visual Studio when the plot fails.

Thank you.

If you are using PGFPlotsX.jl directly, you do not need to use the pgfplotsx() backend. This backend is supposed to work with Plots.jl. It is not required by PGFPlotsX.

If you want to plot a surface using PGPlotsX, you should try something like this:

using PGFPlotsX
using LaTeXStrings

w = range(0; stop = 2π, length = 40)
v = range(0; stop = 2π, length = 40)
f(w,v)= sin(w)*sin(v)

fig = @pgf Axis(
    {
        #view = (0, 90), #to rotate the figure set "view" to true
        colorbar,
        "colormap/viridis",
        #"colormap/jet",
        height = "10cm",
        width = "16cm",
        grid = "major",
        xlabel = L"w",
        ylabel = L"v",
        title = "A nice plot",
    },
    
    Plot3(
        {
            surf,
            #shader = "flat",
        },
        Coordinates(w, v, @. (f(w, v')))
    )
)

The output in VSCode is the following (it works in Atom and Jupyter as well):

julia> using PGFPlotsX
       using LaTeXStrings
       
       w = range(0; stop = 2π, length = 40)
       v = range(0; stop = 2π, length = 40)
       f(w,v)= sin(w)*sin(v)
       
       fig = @pgf Axis(
           {
               #view = (0, 90), #to rotate the figure set "view" to true
               colorbar,
               "colormap/viridis",
               #"colormap/jet",
               height = "10cm",
               width = "16cm",
               grid = "major",
               xlabel = L"w",
               ylabel = L"v",
               title = "A nice plot",
           },
       
           Plot3(
               {
                   surf,
                   #shader = "flat",
               },
               Coordinates(w, v, @. (f(w, v')))
           )
       )
ERROR: PGFPlotsX.MissingExternalProgramError("No LaTeX installation found, figures will not be generated. Make sure either pdflatex, xelatex or lualatex are installed and that the PATH variable is correctly set.")
Stacktrace:
  [1] latexengine()
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/pUwhF/src/build.jl:19
  [2] save(filename::String, td::TikzDocument)
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/pUwhF/src/tikzdocument.jl:73
  [3] #save#69
    @ ~/.julia/packages/PGFPlotsX/pUwhF/src/tikzpicture.jl:34 [inlined]
  [4] save
    @ ~/.julia/packages/PGFPlotsX/pUwhF/src/tikzpicture.jl:34 [inlined]
  [5] save(filename::String, axislike::Axis; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/pUwhF/src/axislike.jl:45
  [6] save
    @ ~/.julia/packages/PGFPlotsX/pUwhF/src/axislike.jl:45 [inlined]
  [7] display(d::PGFPlotsX.PGFPlotsXDisplay, p::Axis)
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/pUwhF/src/tikzdocument.jl:356
  [8] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
  [9] #invokelatest#2
    @ ./essentials.jl:716 [inlined]
 [10] invokelatest
    @ ./essentials.jl:714 [inlined]
 [11] (::VSCodeServer.var"#65#69"{Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:176
 [12] withpath(f::VSCodeServer.var"#65#69"{Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/repl.jl:184
 [13] (::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:153
 [14] hideprompt(f::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/repl.jl:36
 [15] (::VSCodeServer.var"#63#67"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:124
 [16] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:511
 [17] with_logger
    @ ./logging.jl:623 [inlined]
 [18] (::VSCodeServer.var"#62#66"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:201
 [19] #invokelatest#2
    @ ./essentials.jl:716 [inlined]
 [20] invokelatest(::Any)
    @ Base ./essentials.jl:714
 [21] macro expansion
    @ ~/.vscode/extensions/julialang.language-julia-1.6.17/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
 [22] (::VSCodeServer.var"#60#61")()
    @ VSCodeServer ./task.jl:429

It gets the same error.

I run the codes in vscode. I have installed LaTeX.

should I install some LaTex extensions in vscode?

In your case, does that piece of code work in Atom?

Yes, it works well in Atom.

The problem is not related to PGFPlotsX because it renders the plot in Atom. In my case, I have a local LaTeX installation (Tex live) in a Linux Ubuntu system, and the code works there. It also works on a Windows 10 machine with MiKTeX locally installed. In both, the PGFPlotsX’s version is 1.5.0.

Maybe, raise an issue next to the Julia language extension for VSCode.

ERROR: No LaTeX installation found, figures will not be generated. Make sure either pdflatex, xelatex or lualatex are installed and that the PATH variable is correctly set.

I think it is the problem of PATH, Maybe I should set the environment path