Trying to plot, getting no output

I’m running the code below (using Julia 1.8.5) but getting no output other than the below. That is, I don’t see any plot popping up.

➜  julia julia plot-sine.jl
    Updating registry at `~/.julia/registries/General`
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.8/Project.toml`
  No Changes to `~/.julia/environments/v1.8/Manifest.toml`
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.8/Project.toml`
  No Changes to `~/.julia/environments/v1.8/Manifest.toml`

Here is the code:

import Pkg; Pkg.add("Plots"); Pkg.add("PyPlot") # or  Pkg.add("PlotlyJS")
using Plots
pyplot()             # or plotlyjs()
plot(sin, -2pi, pi, label="sine function")

Addendum.. I changed the last part of the code to

plt = plot(sin, -2pi, pi, label="sine function")
display(plt)

Now a plot flashes onto the screen for a fraction of a second, then disappears. No doubt
because the program has terminated.

Addendum 2.. OK, I fixed it: run with julia -i

1 Like

You can also try wait(display(plot(...))) if you don’t want to run it interactively.

1 Like

Excellent! That is what I will do.