# An exemple in order to save figures generated by PGFPlotsX

**URL:** https://discourse.julialang.org/t/an-exemple-in-order-to-save-figures-generated-by-pgfplotsx/38120
**Category:** Visualization
**Tags:** pgfplotsx
**Created:** [April 24, 2020, 1:44am UTC](https://discourse.julialang.org/t/an-exemple-in-order-to-save-figures-generated-by-pgfplotsx/38120 "2020-04-24T01:44:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aquarelle332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarelle332/32/20816_2.png) [@aquarelle332](https://discourse.julialang.org/u/aquarelle332)
#### Post date: [April 24, 2020, 1:44am UTC](https://discourse.julialang.org/t/an-exemple-in-order-to-save-figures-generated-by-pgfplotsx/38120/1 "2020-04-24T01:44:21Z")

</div>

_Julia 1.4.1_  
\*Kubuntu 18.04 LST \*  
_LaTeX + textlive-full (including LuaLaTeX) + ImageMagik_  
_Documentation: PGFPlotsX.jl by Kristoffer Carlsson_

Hello dear all,

Say that I am using an elementary code as follows, extracted from the [here](https://kristofferc.github.io/PGFPlotsX.jl/stable/examples/gallery.html#manual_gallery-1):

```julia
using PGFPlotsX
using LaTeXStrings

@pgf Axis(
    {
        xlabel = L"x",
        ylabel = L"f(x) = x^2 - x + 4"
    },
    Plot(
        Expression("x^2 - x + 4")
    )
)

```

In the documentation I note the general way to export .tex file or .svg figure

```julia
pgfsave(filename::AbstractString, figure; include_preamble::Bool = true, dpi = 150)

```

However I don’t see **how to do in practice in order to obtain** :

- a .tex file which can be compiled in Kile for exemple

- a figure.svg (or .pdf) to be saved.

I lauch prgms from a console with the command julia simple.jl

Thank you in advance for any reply,  
Thierry

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 24, 2020, 6:10am UTC](https://discourse.julialang.org/t/an-exemple-in-order-to-save-figures-generated-by-pgfplotsx/38120/2 "2020-04-24T06:10:22Z")

</div>

I am not sure if you read

[https://kristofferc.github.io/PGFPlotsX.jl/stable/man/save.html](https://kristofferc.github.io/PGFPlotsX.jl/stable/man/save.html)

In any case,

```julia
p = @pgf Axis(
    {
        xlabel = L"x",
        ylabel = L"f(x) = x^2 - x + 4"
    },
    Plot(
        Expression("x^2 - x + 4")
    )
)

pgfsave("/tmp/x.tex", p)
pgfsave("/tmp/x.pdf", p)

```

works fine for me (I don’t know what Kile is, but the `.tex` file compiles find with `pdflatex`).

---

<div class="post-metadata">

### Author: ![aquarelle332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarelle332/32/20816_2.png) [@aquarelle332](https://discourse.julialang.org/u/aquarelle332)
#### Post date: [April 24, 2020, 8:19am UTC](https://discourse.julialang.org/t/an-exemple-in-order-to-save-figures-generated-by-pgfplotsx/38120/3 "2020-04-24T08:19:33Z")

</div>

Thank you very much Tamas\_Papp. Indeed the pgfsave instruction as you wrote it perfectly works.

I am sorry to have bothered you. These last days I read so much documentation about both"Gaston/Gnuplot" and “PGFPlotsX” that I couln’t find my way alone.

[Kile](https://kile.sourceforge.io/) is an integrated LaTeX editing environment.

Kind rgards,  
T.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 24, 2020, 8:43am UTC](https://discourse.julialang.org/t/an-exemple-in-order-to-save-figures-generated-by-pgfplotsx/38120/4 "2020-04-24T08:43:42Z")

</div>

> [@aquarelle332](#):
>
> I am sorry to have bothered you.

You haven’t (and I don’t think anything I wrote was meant to give that impression), as you did not contact me directly, just asked the question here and I was happy to help.

Enjoy PGFPlotsX, which is a therapeutic device for mitigating obsessive-compulsive visualization disorder, disguised as a Julia package.

---

<div class="post-metadata">

### Author: ![aquarelle332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarelle332/32/20816_2.png) [@aquarelle332](https://discourse.julialang.org/u/aquarelle332)
#### Post date: [April 24, 2020, 10:20am UTC](https://discourse.julialang.org/t/an-exemple-in-order-to-save-figures-generated-by-pgfplotsx/38120/5 "2020-04-24T10:20:53Z")

</div>

Excellent! 😀
