Open multiple figure windows using Plots

bernardofpc
Fri, 18 Jul 2025 21:49:37 +0000
Visualization

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()

9 posts - 5 participants