# Solved - (cairomakie) Saving 2 figures - but one figure is saved twice

**URL:** <https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107>\
**Category:** New to Julia\
**Created:** [July 26, 2023, 10:09am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107 "2023-07-26T10:09:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymooseCanad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anonymoosecanad/32/51822_2.png) [@anonymooseCanad](https://discourse.julialang.org/u/anonymooseCanad)\
**Post date:** [July 26, 2023, 10:09am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/1 "2023-07-26T10:09:42Z")

</div>

Hi, my name is M and I am looking for some help.

**Project Context:** I am working on environmental analysis using Julia and DataCubes.  
**Coding Problem:** My code works. Everything is good. Except for saving my figures. First I create a histogram, which I then save as a figure. Next, I create a figure using GeoMakie and the figure is displayed correctly when the display(fig) command is executed, however when I attempt to save the figure with savefig(“Images/FileName2”), the file being saved is the previous figure, although the name is correct.  
  
  
Is it possible that I am not clearing the “canvas” where the figures are being plotted? How can one do this? I apologize for the basic noob questions, but I have spent 8 hours on this and looking in the internet and chatgpt have not yielded me the hoped for results.  
  
  
Thanks so much in advanced for your time and patience.

🙂 m

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 26, 2023, 10:17am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/2 "2023-07-26T10:17:10Z")

</div>

I think it would be helpful for you to create an MWE as explained here [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

i.e. something like:

```julia
using GeoMakie
p1 = plot(something) # I don't actually know how GeoMakie works
savefig("file1")
p2 = plot(something_else)
savefig("file2")

```

which reproduces your problem with some dummy data so that people can see for themselves what’s going on.

---

<div class="post-metadata">

**Author:** ![anonymooseCanad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anonymoosecanad/32/51822_2.png) [@anonymooseCanad](https://discourse.julialang.org/u/anonymooseCanad)\
**Post date:** [July 26, 2023, 10:34am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/3 "2023-07-26T10:34:29Z")

</div>

Would it also be allowed for me to make a github repo with my code and share that?

---

<div class="post-metadata">

**Author:** ![Fliks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fliks/32/2494_2.png) [@Fliks](https://discourse.julialang.org/u/Fliks)\
**Post date:** [July 26, 2023, 10:35am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/4 "2023-07-26T10:35:44Z")

</div>

What happens if you save the fig explicitly?  
`save("filename.png", fig)`

I am also not sure, where the savefig function comes from because that I think is from the Plots.jl ecosystem.

---

<div class="post-metadata">

**Author:** ![anonymooseCanad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anonymoosecanad/32/51822_2.png) [@anonymooseCanad](https://discourse.julialang.org/u/anonymooseCanad)\
**Post date:** [July 26, 2023, 10:39am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/5 "2023-07-26T10:39:59Z")

</div>

I first save my histogram:

> savefig(“Images/histogram\_plot.png”)

And then my Map:

> savefig(“Images/NorthAmerica\_GS\_Trends.png”)

I can also post my github project repo link if that would help, and I could show where exactly the problem occurs?

---

<div class="post-metadata">

**Author:** ![anonymooseCanad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anonymoosecanad/32/51822_2.png) [@anonymooseCanad](https://discourse.julialang.org/u/anonymooseCanad)\
**Post date:** [July 26, 2023, 10:40am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/6 "2023-07-26T10:40:43Z")

</div>

Oh funny that you should be here, I wrote you recently (a month or two back) about my project. I am using your YAXArrays package!

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [July 26, 2023, 11:01am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/7 "2023-07-26T11:01:59Z")

</div>

An MWE too long to fit in a comment is not M enough to W as an E.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 26, 2023, 11:12am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/8 "2023-07-26T11:12:09Z")

</div>

I mean (almost) everything’s allowed, we’re not the posting police, but by my estimation you’re 374% more likely to get quick help if you provide people with a small (in this case I guess it can be \<10 lines of code) example that they can run on their own machines to investigate.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [July 26, 2023, 11:14am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/9 "2023-07-26T11:14:55Z")

</div>

Take a look at @nilshg 's example for structure. It should be something I can copy-paste into my REPL and have it work. You can make some toy data with `rand()` - the plots don’t have to be your real plots.

---

<div class="post-metadata">

**Author:** ![anonymooseCanad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anonymoosecanad/32/51822_2.png) [@anonymooseCanad](https://discourse.julialang.org/u/anonymooseCanad)\
**Post date:** [July 26, 2023, 11:30am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/10 "2023-07-26T11:30:26Z")

</div>

I solved the problem. Instead of using

> savefig(“FileName.png”)  
> I used what I found in a CairoMakie script  
> save(“FileName.png”, fig)

You all have good points. If it’s worth your time and of interest, I can explain my situation.

- I am not a skilled programmer and I have limited experience with debugging. It is a new skill that I need to practice.
- As I am new to this all, I do not yet know the “codex of coders” if you will. In the future, I will try to make a MWE. In this case, I do not understand all of the code well enough to create a MWE for my specific example from scratch.

Thank you everybody for commenting and providing input, I appreciate your time.

kind regards  
m

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 26, 2023, 11:49am UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/11 "2023-07-26T11:49:49Z")

</div>

Glad you got it to work. I would really encourage you to put some effort into the whole MWE thing when asking for help - not just because providing an MWE means you’re much more likely to get help quickly, but also because it teaches you good problem-solving habits when coding.

The process of really trying to narrow things down, thinking through which parts of a larger codebase you need to run to produce a certain error from scratch, will very often make you see the issue more clearly. Many times when I find myself in these situations I find the solution to my problem when trying to narrow it down to an MWE, as it makes me think harder about what exactly is going wrong and where.

As an example, yesterday I ran some old Pluto notebooks for the first time on the recently released Julia 1.10 alpha, and was faced with some pretty inscrutable errors about “parser failure, falling back to flisp” which didn’t mean anything to me. In trying to cut down the notebook enough to reproduce the error minimally, I found this issue which I filed as a bug with `JuliaSyntax`:

> <https://github.com/JuliaLang/JuliaSyntax.jl/issues/332>
>
> As discussed on Slack:
> 
> Noticed this when runnning some old code that had a Val…ue (million US$) in a mardown block. In 1.9:
> \`\`\`
> julia\> md""" ( $ ) """
> ( $ )
>  
> julia\> md""" ($ ) """
> ($ )
>  
> julia\> md""" ( $) """
> ( $)
> \`\`\`
> 
> in 1.10:
> \`\`\`
> julia\> md""" ( $ ) """
> ( $ )
>  
> julia\> md""" ($ ) """
> ($ )
>  
> julia\> md""" ( $) """
> ┌ Error: JuliaSyntax parser failed — falling back to flisp!
> │ exception =
> │ BoundsError: attempt to access empty SubString{String} at index \[0\]
> \`\`\`
> I can work around this by escaping the $ but I guess it's a regression from the old parser.

As you’ll see there, the MWE ended up being:

```julia
julia> using Markdown

julia> md"$)"
┌ Error: JuliaSyntax parser failed — falling back to flisp!

```

so I managed to go down from a \>1,000 LOC notebook to six characters!

---

<div class="post-metadata">

**Author:** ![anonymooseCanad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anonymoosecanad/32/51822_2.png) [@anonymooseCanad](https://discourse.julialang.org/u/anonymooseCanad)\
**Post date:** [July 26, 2023, 12:25pm UTC](https://discourse.julialang.org/t/solved-cairomakie-saving-2-figures-but-one-figure-is-saved-twice/102107/12 "2023-07-26T12:25:58Z")

</div>

I see, I see. That’s really a good point. Thanks for taking your time to share the process and providing an example of it at work. I will keep this in mind for future struggles 🙂
