# Save plot as .tex file

**URL:** <https://discourse.julialang.org/t/save-plot-as-tex-file/108691>\
**Category:** Visualization\
**Tags:** latex, plots, pgfplotsx\
**Created:** [January 11, 2024, 3:30pm UTC](https://discourse.julialang.org/t/save-plot-as-tex-file/108691 "2024-01-11T15:30:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![flobe](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@flobe](https://discourse.julialang.org/u/flobe)\
**Post date:** [January 11, 2024, 3:30pm UTC](https://discourse.julialang.org/t/save-plot-as-tex-file/108691/1 "2024-01-11T15:30:55Z")

</div>

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

```julia
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:

```julia
ERROR: KeyError: key :label not found

```

Not sure what I’m doing wrong here …

Thanks for any advice 🙏

---

<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:** [January 11, 2024, 4:00pm UTC](https://discourse.julialang.org/t/save-plot-as-tex-file/108691/2 "2024-01-11T16:00:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![flobe](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@flobe](https://discourse.julialang.org/u/flobe)\
**Post date:** [January 12, 2024, 8:11am UTC](https://discourse.julialang.org/t/save-plot-as-tex-file/108691/3 "2024-01-12T08:11:11Z")

</div>

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

```julia
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)

```

---

<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:** [January 12, 2024, 8:44am UTC](https://discourse.julialang.org/t/save-plot-as-tex-file/108691/4 "2024-01-12T08:44:34Z")

</div>

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

```julia
using Pkg
Pkg.status()
versioninfo()

```

?

---

<div class="post-metadata">

**Author:** ![flobe](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@flobe](https://discourse.julialang.org/u/flobe)\
**Post date:** [January 12, 2024, 9:06am UTC](https://discourse.julialang.org/t/save-plot-as-tex-file/108691/5 "2024-01-12T09:06:13Z")

</div>

> [@BeastyBlacksmith](#):
>
> ```julia
> 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 =

---

<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:** [January 12, 2024, 9:17am UTC](https://discourse.julialang.org/t/save-plot-as-tex-file/108691/6 "2024-01-12T09:17:30Z")

</div>

> [@flobe](#):
>
> Plots v1.38.4

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

```julia
using Pkg
Pkg.update("Plots")

```

---

<div class="post-metadata">

**Author:** ![flobe](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@flobe](https://discourse.julialang.org/u/flobe)\
**Post date:** [January 12, 2024, 9:31am UTC](https://discourse.julialang.org/t/save-plot-as-tex-file/108691/7 "2024-01-12T09:31:08Z")

</div>

> [@BeastyBlacksmith](#):
>
> `Pkg.status()`

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
