JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
478 stars 88 forks source link

Can't writemime plots #55

Open Keno opened 10 years ago

Keno commented 10 years ago

I was expecting to be able to do

open(file->writemime(file,"image/png",PyPlot.streamplot(args...)),"test.png","w"))

In order to save a PyPlot plot (this works for e.g. Gadfly/Winston). Any chance that could be supported?

stevengj commented 10 years ago

You can do this, but you need to pass a Figure object, e.g. via gcf():

open(file -> writemime(file, "image/png", gcf()), "test.png", "w")

The Matplotlib plotting functions typically don't return the Figure object, e.g. returning a Lines2D object or some such thing; I guess this is because they may refer to only part of the figure. I could change them to return gcf(), of course, but I'm reluctant to change the Matplotlib API too much.

You could also just do savefig("test.png").

Keno commented 10 years ago

While I see the rationality of not wanting to change the matplotlib API too much, it's also somewhat annoying (especially since I can't just display() it). Nevertheless, if you can't see a way to make both work (maybe by having display and writemime implicitly draw the whole plot even if passed only part?), I won't complain.