Saving figures with plot()

748 views
Skip to first unread message

Amit Saha

unread,
Jul 6, 2013, 1:31:24 PM7/6/13
to sy...@googlegroups.com
This is something which was not obvious to me (or I don't read well),
so posting it in case it helps someone:

>>> from sympy import plot
>>> from sympy import Symbol

>>> x=Symbol('x')
>>> p = plot(2*x+3,show=False)

Now, you have a object of the Plot class returned in p.

So, you can either see the graph now:
>>> p.show()

Or save it:

>>> p.save('/tmp/foo1.png')

Aaron Meurer

unread,
Jul 6, 2013, 2:43:31 PM7/6/13
to sy...@googlegroups.com
Yes, our documentation for plot() could be better (pull requests welcome!). Basically, plot(show=False) just returns the matplotlib object, and so you can call all the normal matplotlib functions on it.

Aaron Meurer



--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.



Stefan Krastanov

unread,
Jul 6, 2013, 3:02:51 PM7/6/13
to sy...@googlegroups.com
A small correction: It is not a matplotlib object. However, if you use
the matplotlib backend
you can access the encapsulated matplotlib objects through `p._backend`.

Amit Saha

unread,
Jul 6, 2013, 6:52:42 PM7/6/13
to sy...@googlegroups.com
On Sun, Jul 7, 2013 at 5:02 AM, Stefan Krastanov
<krastano...@gmail.com> wrote:
> A small correction: It is not a matplotlib object. However, if you use
> the matplotlib backend
> you can access the encapsulated matplotlib objects through `p._backend`.

Indeed, thanks guys.
http://echorand.me

Amit Saha

unread,
Jul 6, 2013, 6:55:24 PM7/6/13
to sy...@googlegroups.com
On Sun, Jul 7, 2013 at 4:43 AM, Aaron Meurer <asme...@gmail.com> wrote:
> Yes, our documentation for plot() could be better (pull requests welcome!).
> Basically, plot(show=False) just returns the matplotlib object, and so you
> can call all the normal matplotlib functions on it.

Okay, I will try to go over the documentation for sending a pull
request and will try to make some small contributions.
--
http://echorand.me
Reply all
Reply to author
Forward
0 new messages