Plotting with Plots.jl

How can I generate a two plots using Plots.jl and GR as the backend within the same window. I am using the following code from one of the book but plots appear in two separate windows. The book uses Pyplot.jl.

using Plots, StatsBase
# Sampling with withReplacement
function proportionFished(gF,sF,numberFished,N,withReplacement = false)
    function fishing()
        fishInPond = [ones(Int64,gF); zeros(Int64,sF)]
        fishCaught = Int64[]
        for fish in 1:numberFished
            fished = rand(fishInPond)
            if withReplacement == false
                deleteat!(fishInPond, findfirst(x->x==fished, fishInPond))
    simulations = [fishing() for _ in 1:N]
    proportions = counts(simulations,0:numberFished)/N
    if withReplacement
        plot!(0:numberFished,proportions,linestyle = :dot, linetype=:sticks, markershape=:hexagon,label="With replacement",legend=:topleft);
        plot!(0:numberFished,proportions, label="Without replacement",legend=:topleft,linetype=:sticks,linestyle = :dot,color="blue")
N = 10^5;
goldFish, silverFish, numberFished = 3, 4, 3;
proportionFished(goldFish, silverFish, numberFished, N)
proportionFished(goldFish, silverFish, numberFished, N, true)

Just create two plots and plot them together. E.g. replace the plot!() call with a plot() call and do

p1 = proportionFished(goldFish, silverFish, numberFished, N)
p2 = proportionFished(goldFish, silverFish, numberFished, N, true)
plot(p1, p2)

if I do as you suggested they get displayed side by side. What I am looking for is that they get merged into just one plot. May be I was not clear in my question.

ah, OK. Pass the plot to the function as a parameter.

p = plot()
proportionFished(p, goldFish, silverFish, numberFished, N)
proportionFished(p, goldFish, silverFish, numberFished, N, true)

then change the implementation inside the function to

 plot!(p, 0:numberFished,proportions,linestyle = :dot, linetype=:sticks, markershape=:hexagon,label="With replacement",legend=:topleft);
1 Like

@mkborregaard. Thanks
it works but it is still creating 3 plots in three separate windows, one blank plot, 2nd plot for “without replacement” and 3nd plot combining the two .

PS: I just put semicolon at the end of first two statements and it now creates only one window.