# How do I save a plot?

**URL:** <https://discourse.julialang.org/t/how-do-i-save-a-plot/35370>\
**Category:** Visualization\
**Created:** [March 1, 2020, 6:43pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370 "2020-03-01T18:43:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [March 1, 2020, 6:43pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370/1 "2020-03-01T18:43:23Z")

</div>

```julia
julia> out = DataFrame(Q1 = [3,3,3], Q2 = [3,2,1])
3×2 DataFrame
│ Row │ Q1 │ Q2 │
│ │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1 │ 3 │ 3 │
│ 2 │ 3 │ 2 │
│ 3 │ 3 │ 1 │

julia> fig1 = pie([out.Q1], [1,2])

julia> fig1 = pie([out.Q1], [1,2,3])

julia> savefig(fig1)

```

So, I’m trying to save a pie chart from plots, created from a data frame.

When I do I get an error:

```julia
ERROR: MethodError: no method matching savefig(::Plots.Plot{Plots.GRBackend})

```

Is this to do with GRBackend, or do I need to add more details, like file type and location?

---

<div class="post-metadata">

**Author:** ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)\
**Post date:** [March 1, 2020, 7:27pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370/2 "2020-03-01T19:27:34Z")

</div>

Check the function parameters, you are missing the filename. Use ?savefig in the REPL to get the help.

---

<div class="post-metadata">

**Author:** ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)\
**Post date:** [March 1, 2020, 7:29pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370/3 "2020-03-01T19:29:08Z")

</div>

The second parameter is the output file location. The file type is deduced from the extension (png, svg…).

The error message gives you a hint:

```julia
ERROR: MethodError: no method matching savefig(::Plots.Plot{Plots.GRBackend})
Closest candidates are:
  savefig(::Plots.Plot, ::AbstractString) at /home/user/.julia/packages/Plots/qZHsp/src/output.jl:107
  ...

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [March 1, 2020, 7:53pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370/4 "2020-03-01T19:53:28Z")

</div>

```julia
savefig(fig1,"C:/Users/brett/OneDrive/Documents/Soc323")

```

I did this, and did not get an error message, but no .png showed up in the destination folder.

Edit. I need to specify the file.

```julia
savefig(fig1,"C:/Users/brett/OneDrive/Documents/Soc323/fig1.png")

```

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [March 1, 2020, 11:28pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370/5 "2020-03-01T23:28:22Z")

</div>

If you save several figures to the same directory, it is easier if you define a fig path:

```julia
figpath = "C:/Users/brett/OneDrive/Documents/Soc323/"
savefig(fig1,figpath*"fig1.png")
savefig(fig1,figpath*"fig1.svg")
savefig(fig1,figpath*"fig1.pdf")
# etc.

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [March 1, 2020, 11:29pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370/6 "2020-03-01T23:29:41Z")

</div>

Thanks, I figured it out and should have replied. Also, display(fig1), allows the figure to appear in a pdf.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 2, 2020, 2:42am UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370/7 "2020-03-02T02:42:52Z")

</div>

```julia
help?> savefig
search: savefig StackOverflowError

  savefig([plot,] filename)

  Save a Plot (the current plot if plot is not passed) to file. The file type is inferred from the file extension.

```

---

<div class="post-metadata">

**Author:** ![Nav](https://avatars.discourse-cdn.com/v4/letter/n/6a8cbe/32.png) [@Nav](https://discourse.julialang.org/u/Nav)\
**Post date:** [September 3, 2022, 1:41pm UTC](https://discourse.julialang.org/t/how-do-i-save-a-plot/35370/8 "2022-09-03T13:41:29Z")

</div>

Would be great to eventually have an option to save plots and tables to a zip file or to a database or to send the plot and table to a queue like RabbitMQ.
