# Julia crashes when saving PyPlot figure

**URL:** <https://discourse.julialang.org/t/julia-crashes-when-saving-pyplot-figure/115056>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 1, 2024, 12:46pm UTC](https://discourse.julialang.org/t/julia-crashes-when-saving-pyplot-figure/115056 "2024-06-01T12:46:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![u645532](https://avatars.discourse-cdn.com/v4/letter/u/74df32/32.png) [@u645532](https://discourse.julialang.org/u/u645532)\
**Post date:** [June 1, 2024, 12:46pm UTC](https://discourse.julialang.org/t/julia-crashes-when-saving-pyplot-figure/115056/1 "2024-06-01T12:46:40Z")

</div>

I’m using Julia 1.10.3 with PyPlot (matplotlib 3.8.4)…

> using PyPlot  
> loglog([0.001,0.1,1,10],[1e4,3e3,2e2,1e1],“o-”)

… I save this figure using the Save button in the figure window, this works. Then I close the window and display a new figure:

> loglog([0.001,0.1,1,10],[1e4,3e3,2e2,1e1],“o-”)

… When I press the Save button in this new figure window, Julia crashes:

[4966] signal (10.1): Bus error: 10  
in expression starting at none:0  
lookUpImpOrNilTryCache at /usr/lib/libobjc.A.dylib (unknown line)  
Allocations: 5144613 (Pool: 5140625; Big: 3988); GC: 7  
Bus error: 10

In general, Julia with PyPlot crashes at the second attempt to save a figure. Does anybody know this problem and how to resolve it?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [June 1, 2024, 3:32pm UTC](https://discourse.julialang.org/t/julia-crashes-when-saving-pyplot-figure/115056/2 "2024-06-01T15:32:43Z")

</div>

Have you tried PythonPlot.jl?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 2, 2024, 1:07pm UTC](https://discourse.julialang.org/t/julia-crashes-when-saving-pyplot-figure/115056/3 "2024-06-02T13:07:00Z")

</div>

> [@u645532](#):
>
> loglog([0.001,0.1,1,10],[1e4,3e3,2e2,1e1],“o-”)

I tried your example and it works fine for me (on Ubuntu 22.04).

Can you post the output of:

```julia
using Pkg
Pkg.status()

```

and also the output of:

```julia
versioninfo()

```

?

---

<div class="post-metadata">

**Author:** ![u645532](https://avatars.discourse-cdn.com/v4/letter/u/74df32/32.png) [@u645532](https://discourse.julialang.org/u/u645532)\
**Post date:** [June 2, 2024, 1:43pm UTC](https://discourse.julialang.org/t/julia-crashes-when-saving-pyplot-figure/115056/4 "2024-06-02T13:43:28Z")

</div>

@ufechner7: Thanks for looking into this!  
The problem with crashes of julia at a second attempt to save a figure are not new, I had the same problem with julia 1.9.  
Also, when I load Metal and PyPlot in one line:

> using Metal, PyPlot

julia crashes. When I load one after the other:

> using PyPlot  
> using Metal

I can load both packages and julia does not crash.  
Here’s the info you ask for:

**julia\>** Pkg.status()  
**Status** `~/.julia/environments/v1.10/Project.toml`  
[f67ccb44] HDF5 v0.17.2  
[7073ff75] IJulia v1.24.2  
[dde4c033] Metal v1.1.0  
[f27b6e38] Polynomials v4.0.9  
[d330b81b] PyPlot v2.11.2

**julia\>** versioninfo()  
Julia Version 1.10.3  
Commit 0b4590a5507 (2024-04-30 10:59 UTC)  
Build Info:  
Official [https://julialang.org/](https://julialang.org/) release  
Platform Info:  
OS: macOS (arm64-apple-darwin22.4.0)  
CPU: 10 × Apple M1 Max  
WORD\_SIZE: 64  
LIBM: libopenlibm  
LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)  
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

---

<div class="post-metadata">

**Author:** ![cgarling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgarling/32/29278_2.png) [@cgarling](https://discourse.julialang.org/u/cgarling)\
**Post date:** [June 3, 2024, 2:51am UTC](https://discourse.julialang.org/t/julia-crashes-when-saving-pyplot-figure/115056/5 "2024-06-03T02:51:51Z")

</div>

I often use pyplot.jl on apple m2 with python 3.11.1 and matplotlib 3.6.2. Might help to know if you can save two figures consecutively when using matplotlib natively from python – make sure it’s not an issue on the python side.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 3, 2024, 3:15am UTC](https://discourse.julialang.org/t/julia-crashes-when-saving-pyplot-figure/115056/6 "2024-06-03T03:15:37Z")

</div>

> [@cgarling](#):
>
> Might help to know if you can save two figures consecutively when using matplotlib natively from python

Would also be good to see if it is a backend problem. Check the value of `PyPlot.backend` to see what backend you are using, and make sure you are using the same backend in Python (by setting the `MPLBACKEND` environment variable), or try switching to a different backend.

You can also try saving figures with `savefig("foo.png")` or `savefig("bar.pdf")`, for example, rather than using the GUI.
