# Plots do not display, unless I call gui(), when using custom sysimage

**URL:** <https://discourse.julialang.org/t/plots-do-not-display-unless-i-call-gui-when-using-custom-sysimage/92207>\
**Category:** General Usage\
**Tags:** plots, sysimage\
**Created:** [December 28, 2022, 1:36am UTC](https://discourse.julialang.org/t/plots-do-not-display-unless-i-call-gui-when-using-custom-sysimage/92207 "2022-12-28T01:36:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdiaz02](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@rdiaz02](https://discourse.julialang.org/u/rdiaz02)\
**Post date:** [December 28, 2022, 1:36am UTC](https://discourse.julialang.org/t/plots-do-not-display-unless-i-call-gui-when-using-custom-sysimage/92207/1 "2022-12-28T01:36:48Z")

</div>

I have created a custom sysimage that contains Plots, as explained here

[https://julialang.github.io/PackageCompiler.jl/dev/examples/plots.html](https://julialang.github.io/PackageCompiler.jl/dev/examples/plots.html)

(see [1] below for complete details).

If I start Julia from the REPL using that sysimage and I try to plot

```julia
using Plots
plot(rand(1))

```

I get

```julia
Plot{Plots.GRBackend() n=1}

```

Same thing happens (i.e., no plot is displayed) even if I do

```julia
p1 = plot(rand(3))
display(p1)

```

I need to do `gui()` (or `gui(plot(rand(1)))` or `plot(rand(1), show = true)`) for the plot to be displayed.

If I start Julia without the sysimage, or with other sysimages I’ve created that do not contain Plots, everything works as expected (`plot` displays the plot in a window without needing to use `gui`). And I’d be willing to bet this did not happen to me before (e.g., with Julia 1.8.2).

I think I have broken something, but I just reinstalled Julia from scratch and removed the `~/.julia` directory before installing packages again, so I can’t understand what is happening.

(Note: a somewhat similar thing has been asked about Makie: [Makie doesn't display plot when using a custom Julia sysimage](https://discourse.julialang.org/t/makie-doesnt-display-plot-when-using-a-custom-julia-sysimage/38515), but my question is about Plots —I do not have Makie installed).

```julia
Julia> versioninfo()
Julia Version 1.8.4
Commit 00177ebc4fc (2022-12-23 21:32 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Xeon(R) CPU E3-1505M v5 @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores

(@v1.8) pkg> st --manifest Plots
Status `~/.julia/environments/v1.8/Manifest.toml`
  [91a5bcdd] Plots v1.38.0

@v1.8) pkg> st --manifest PackageCompiler
Status `~/.julia/environments/v1.8/Manifest.toml`
  [9b87118b] PackageCompiler v2.1.2

```

* * *

[1] Custom image creation and use:

1. Create file `precompile_plots.jl` that contains

```julia
using Plots
p = plot(rand(2,2))
display(p)

```

1. Start Julia and type

```julia
using PackageCompiler
create_sysimage(["Plots"], sysimage_path="sys_plots.so", precompile_execution_file="precompile_plots.jl")

```

1. Finally, start Julia as

`julia --sysimage sys_plots.so`

and, in the REPL type

```julia
using Plots
plot(rand(1))

```

---

<div class="post-metadata">

**Author:** ![rdiaz02](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@rdiaz02](https://discourse.julialang.org/u/rdiaz02)\
**Post date:** [December 28, 2022, 5:16pm UTC](https://discourse.julialang.org/t/plots-do-not-display-unless-i-call-gui-when-using-custom-sysimage/92207/2 "2022-12-28T17:16:11Z")

</div>

Answering my own question, an analogous to what has to be done with Makie ([Makie doesn't display plot when using a custom Julia sysimage](https://discourse.julialang.org/t/makie-doesnt-display-plot-when-using-a-custom-julia-sysimage/38515)), one can solve this by running `Plots. __init__ ()` after loading Plots.

(In addition it seems also that if the sysimage contains IJulia, the above will not work, nor will `gui` nor `plot(p, show = true)`; I think this makes sense, but I had a couple of sysimages that, accidentally, included IJulia).

I’ve made a pull request suggesting the use of `Plots. __init__ ()` in the example in [Creating a sysimage for fast plotting with Plots.jl · PackageCompiler](https://julialang.github.io/PackageCompiler.jl/dev/examples/plots.html).

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 16, 2024, 12:47pm UTC](https://discourse.julialang.org/t/plots-do-not-display-unless-i-call-gui-when-using-custom-sysimage/92207/3 "2024-05-16T12:47:10Z")

</div>

What happened to your PR? The example in the docs still does not work as it is.

---

<div class="post-metadata">

**Author:** ![rdiaz02](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@rdiaz02](https://discourse.julialang.org/u/rdiaz02)\
**Post date:** [May 16, 2024, 8:02pm UTC](https://discourse.julialang.org/t/plots-do-not-display-unless-i-call-gui-when-using-custom-sysimage/92207/4 "2024-05-16T20:02:30Z")

</div>

Sorry if I wasn’t clear, and for not linking the PR: I suggested a change to the documentation ( [suggest using Plots.\_\_init\_\_() (#750) · JuliaLang/PackageCompiler.jl@9b6b461 · GitHub](https://github.com/JuliaLang/PackageCompiler.jl/commit/9b6b461352edf389d5f54f60442521a82025dd69) ) and that was incorporated in the documentation. (I haven’t used Julia in a while so I am not sure if things work as of now with the suggested changes; note, though, that there also seemed to be issues with the creation of sysimages that include Plots: [Sysimage creation example with plots does not seem to work](https://discourse.julialang.org/t/sysimage-creation-example-with-plots-does-not-seem-to-work/101269) and [PackageCompiler spins infinitely when compiling sysimage · Issue #825 · JuliaLang/PackageCompiler.jl · GitHub](https://github.com/JuliaLang/PackageCompiler.jl/issues/825) ).
