Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: How to save a figure without plotting/displaying it in PyPlot?

I am using the PyPlot package in Julia to generate and save several figures. My current approach is to display the figure and then save it using savefig.

using PyPlot
a = rand(50,40)
imshow(a)
savefig("a.png")

Is there a way to save the figure without having to first display it?

like image 351
Landon Avatar asked Sep 18 '16 20:09

Landon


1 Answers

Are you using the REPL or IJulia?

If you close the figure then it won't show you the plot. Is that what you want?

a = rand(50,40)
ioff() #turns off interactive plotting
fig = figure()
imshow(a)
close(fig)

If that doesn't work you might need to turn off interactive plotting using ioff() or change the matplotlib backend (pygui(:Agg)) (see here: Calling pylab.savefig without display in ipython)

Remember that most questions about plotting using PyPlot can be worked out by reading answers from the python community. And also using the docs at https://github.com/JuliaPy/PyPlot.jl to translate between the two :)

like image 178
Alexander Morley Avatar answered Sep 23 '22 16:09

Alexander Morley