6
votes

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?

1
If you can sort out how to control the mpl backend, set it to 'Agg'.tacaswell
At a minimum, you can set the backend in your .matplotlibrc file.tacaswell

1 Answers

4
votes

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