Save plot as .tex file

Hi all,

I’m trying to export my plot in Julia as a pgf plot. So basically I want a .tex file with the data, the header, etc. automatically generated from the plot. However I’m not sure how to do it correctly. Currently I’m trying to use this MWE

using Plots
pgfplots()
Plots.plot(1:5)
Plots.plot!(1:5, (1:5).^2, tex_output_standalone = true)
savefig("myline.tex")    

However I get the error:

ERROR: KeyError: key :label not found

Not sure what I’m doing wrong here …

Thanks for any advice :pray:

The pgfplots backend is deprecated for a long time, please use the pgfplotsx backend.

Yes I also have been trying to use pgfplotsx, however than the error message is

ERROR: Invalid pgf key PGFPlotsX.Options(OrderedCollections.OrderedDict{String, Any}("color" => RGBA{Float64}(0.0,0.0,0.0,1.0), "draw opacity" => 1.0, "line width" => 1, "solid" => nothing), false)

I can’t reproduce that, can you provide the output of

using Pkg
Pkg.status()
versioninfo()

?

julia> Pkg.status()
Status /Project.toml

[8314cec4] PGFPlotsX v1.6.0
[f0f68f2c] PlotlyJS v0.18.10
[91a5bcdd] Plots v1.38.4

Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core™ i7-8700 CPU @ 3.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =

Indeed, that version had this bug. Updating Plots should fix that.

using Pkg
Pkg.update("Plots")

Updated to 1.39, same issue. Maybe I also should use a newer Julia version?

EDIT: I updated Julia and all my packages - it’s working