I would like to use scripts, in the REPL, to display multiple figures from a function. Using PyPlot and plt.figure allows it, but Plots does not seem to have a way of doing so.
My MWE:
using Plots
import PyPlot
plt = PyPlot
function test()
x = 1:10
y = rand(10)
p = plot(title="Sample Plot, does not appear")
plot!(p, x, y, label="Random Data")
display(p) # Very weird that this does nothing!
p2 = plot(title="Another Sample Plot", reuse=false)
plot!(p2, x.^2, sqrt.(y), label="More Random Data")
display(p2) # Only this one appears
nothing
end
function test_plt()
x = 1:10
y = rand(10)
plt.figure()
plt.plot(x, y, label="Random Data")
plt.title("Sample Plot with PyPlot")
plt.legend()
plt.figure()
plt.plot(x.^2, sqrt.(y), label="More Random Data")
plt.title("Another Sample Plot with PyPlot")
plt.legend()
nothing
end
test()
test_plt()
This is a backend issue with Plots when using the GRBackend. Depending on OS and perhaps versions, this might work (didnât for me)
ENV["GKSwstype"] = "100" # forces GR to use a GUI window
using Plots
gr() # explicitly set backend
Even setting reuse=false didnât work for me.
It might work wit the PyPlot backend.
For me this issue is one of the reasons not to use Plots.jl.
I use ControlPlots.jl or GLMakie.jl .
1 Like
The only workaround in GR is to enter Command+F to freeze the window.
So to be clear:
GR does not support multiple windows (is there a plan for this?)
- Other backends (
pyplot, gaston, âŚ) do - so one must explicitly use them
One might wonder why GR is the default, thenâŚ
1 Like
With the default Plots.jl gr() backend, the following works on Windows, but as indicated above, the new window is a frozen copy:
using Plots; gr()
plot(sin)
# Click on the plot window to make it the main focus.
# Press the 'F' key to freeze the former plot in a new window
plot(cos)
If I understand what you meant, then, the click then press âFâ must be done before the next plot command. This seems incompatible with the use âin a scriptâ.
Yes, but if you really want to use the gr() backend, you could try simulating the key presses programmatically using the operating system APIs.