Jupyter notebook don't show the plots after loaded sysimaged PyPlot.jl package

I’d like to boost the loading speed of PyPlot.jl in IJulia-Jupyter model. I created sysimage of this package as below:

using PackageCompiler
create_sysimage(:PyPlot, sysimage_path="/path/to/pyplot.so")

and checked this sysimage in REPL mode:
$ Julia -J/path/to/pyplot.so

It works fine. So, I tried to load the sysimage in IJulia by adding a kernel:

using IJulia
installkernel("Julia with PyPlot", "-J/path/to/pyplot.so")

In Jupyter notebook mode, this kernel can be used, and using PyPlot loaded very fast. However, all the figures drew by PyPlot doesn’t show on the notebook webpage. It only shows a text line of PyObject after running plot function.

My Julia version is 1.4.1 in Linux. IJulia 1.21.2, PackageCompiler 1.1.1, PyPlot 2.9.0 .

I can report that this process works for me in 1.4.1 with Plots (with modest speedup on the actual plotting). Did not try PyPlot.

I’m in the same boat.
Found this relevant issue: Plots don't show automatically when PyPlot compiled with PackageCompiler · Issue #476 · JuliaPy/PyPlot.jl · GitHub

You can get the figure to show in the notebook with display(gcf()) (or just end the cell with fig if that’s your figure object).

To actually restore the auto-display behaviour when using PackageCompiler, see this unmerged PR by @xzackli: add a flag which delays the init until IJulia cell by xzackli · Pull Request #480 · JuliaPy/PyPlot.jl · GitHub
It is installable with Pkg.add(url="https://github.com/xzackli/PyPlot.jl")

1 Like