2

I want to display PyPlot figures and relevant text sequentially in an iJuia notebook.

using PyPlot
for i=1:10
    println(i)  #Relevant text info
    fig = figure(figsize=(4,1))
    plot(1:10,rand(10));title(i)
end

This returns figures together, placed at a varying stage of the text output. i.e. something like: 1 2 3 4 5 6 [fig 1] ... [fig 10] 7 8 9 10

Alternatively I've tried using display(fig):

using PyPlot
for i=1:10
    println(i)  #Relevant text info
    fig = figure(figsize=(4,1))
    plot(1:10,rand(10))
    title(i)

    display(fig)
end

But this returns [fig 1] 1 [fig 2] 2 [fig 3] 3 [fig 4] 4 .... [fig 9] 9 [fig 10] [fig 1] ... [fig 10] 10 (duplicating the figures all together at the end)

Is there a way to use display(fig) sequentially without duplication?

Ian
  • 1,427
  • 1
  • 15
  • 27

1 Answers1

2

I have found a solution. Perhaps not the most robust or versatile, but it seems to keep things in order. Using display() to display relevant text keeps the text and figure order correct, and close(fig) just after display(fig) prevents duplicate figs from being shown.

using PyPlot
for i=1:10
    display(i)  #Relevant text info

    fig = figure(figsize=(4,1))
    plot(1:10,rand(10))
    title(i)

    display(fig)
    close(fig)
end

Result: 1 [fig 1] 2 [fig 2] ... 10 [fig 10]

Ian
  • 1,427
  • 1
  • 15
  • 27