lilinjn
lilinjn

Reputation: 355

Disabling automatic display of PyPlot.jl figures in IJulia

Sometimes I have a need to generate a PDF with multiple charts from Julia using PyPlot.jl, but initially I prototype a representative single chart in IJulia. Once I've worked out what I want the charts to look like, it's convenient (because I have a large chunk of data already loaded) to go ahead and generate all figures and the PDF from IJulia as well (though it's not relevant to my issue, in case you are curious, I create the pdf using @pyimport matplotlib.backends.backend_pdf as pdf, etc)

Because pyplot uses some "magic" to automatically display figures created by a given cell, when I run my pdf generator, I unfortunately have a bunch of figures embedded into my cell output.

For now, I have been able to disable this output by doing

plt = PyPlot
showFigs = false
draw_if_interactive() = begin 
    if showFigs 
        plt.draw_if_interactive()
    else
        plt.drew_something[1] = false
    end
end

plt.pltm["draw_if_interactive"] = draw_if_interactive

and then toggling showFigs as needed. Given that this is a monkey patch of a prior monkey patch I'm not entirely sure if I'm now leaking figures -- there is some other "magic" the closes figures automatically, by I'm not sure if my hack has broken that. If someone more familiar with how this works could comment as to whether my approach seems ok, that would be greatly appreciated!

thanks for any help!

Upvotes: 3

Views: 475

Answers (1)

simonster
simonster

Reputation: 556

I think you should be able to call ioff() to disable automatic figure display and ion() to enable it again. These commands alter PyPlot's interactive mode setting.

Upvotes: 3

Related Questions