Julia crashes when saving PyPlot figure

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?

Have you tried PythonPlot.jl?

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

Can you post the output of:

using Pkg
Pkg.status()

and also the output of:

versioninfo()

?

@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/ 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)

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.

1 Like

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.