plot_implicit and legend

505 views
Skip to first unread message

Amit Saha

unread,
Mar 30, 2014, 12:15:36 AM3/30/14
to sy...@googlegroups.com
Hello,

I came across this today:

The problem:

>>> from sympy import plot_implicit, Point, Line
>>> p1 = Point(1, 2)
>>> plot_implicit(Line(p1, slope=1).equation(), legend=True)

/usr/lib64/python3.3/site-packages/matplotlib/axes.py:4749:
UserWarning: No labeled objects found. Use label='...' kwarg on
individual plots.
warnings.warn("No labeled objects found. "
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "./sympy/plotting/plot_implicit.py", line 355, in plot_implicit
p.show()
File "./sympy/plotting/plot.py", line 184, in show
self._backend.show()
File "./sympy/plotting/plot.py", line 965, in show
self.process_series()
File "./sympy/plotting/plot.py", line 953, in process_series
self.ax.legend_.set_visible(parent.legend)
AttributeError: 'NoneType' object has no attribute 'set_visible'


Solution:

The return value of self.ax.legend() should be checked first and then
the call to set_visible() be made:

diff --git a/sympy/plotting/plot.py b/sympy/plotting/plot.py
index 82880b7..8022cba 100644
--- a/sympy/plotting/plot.py
+++ b/sympy/plotting/plot.py
@@ -949,8 +949,8 @@ def process_series(self):
if not parent.axis:
self.ax.set_axis_off()
if parent.legend:
- self.ax.legend()
- self.ax.legend_.set_visible(parent.legend)
+ if self.ax.legend():
+ self.ax.legend_.set_visible(parent.legend)
if parent.margin:
self.ax.set_xmargin(parent.margin)
self.ax.set_ymargin(parent.margin)


>>> plot_implicit(Line(p1, slope=1).equation(), legend=True)
/usr/lib64/python3.3/site-packages/matplotlib/axes.py:4749:
UserWarning: No labeled objects found. Use label='...' kwarg on
individual plots.
warnings.warn("No labeled objects found. "
<sympy.plotting.plot.Plot object at 0x7f4a9c6c2690>


I don't know enough yet why the labeled object cannot be found in this
case, and would appreciate any hints.

Best,
Amit.


--
http://echorand.me

Aaron Meurer

unread,
Apr 12, 2014, 4:40:58 PM4/12/14
to sy...@googlegroups.com
It would be better to submit patches as pull requests, even if you do
not know how to complete them. It is much easier to comment on code in
pull requests than in emals.

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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CANODV3mkihGdPhHwEvWUXDH33%2BtU4o4gXsCk1qj46Rf9%2Bu4H%3DA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Amit Saha

unread,
Apr 13, 2014, 4:19:56 AM4/13/14
to sy...@googlegroups.com
On Sun, Apr 13, 2014 at 6:40 AM, Aaron Meurer <asme...@gmail.com> wrote:
> It would be better to submit patches as pull requests, even if you do
> not know how to complete them. It is much easier to comment on code in
> pull requests than in emals.

Sure, here it is: https://github.com/sympy/sympy/pull/7400 . Please take a look.


Thanks,
Amit.
--
http://echorand.me

Amit Saha

unread,
Apr 20, 2014, 11:54:08 PM4/20/14
to sy...@googlegroups.com
On Sun, Apr 13, 2014 at 6:19 PM, Amit Saha <amits...@gmail.com> wrote:
> On Sun, Apr 13, 2014 at 6:40 AM, Aaron Meurer <asme...@gmail.com> wrote:
>> It would be better to submit patches as pull requests, even if you do
>> not know how to complete them. It is much easier to comment on code in
>> pull requests than in emals.
>
> Sure, here it is: https://github.com/sympy/sympy/pull/7400 . Please take a look.

This patch prevents the crash when "legend" is specified. I am keen to
understand and try to fix why it doesn't work. To restate:

>>> from sympy import Symbol, plot_implicit
>>> x = Symbol('x')
>>> y = Symbol('y')
>>> plot_implicit(2*x+3*y-1, legend='A line')
/usr/lib64/python2.7/site-packages/matplotlib/axes.py:4747:
UserWarning: No labeled objects found. Use label='...' kwarg on
individual plots.
warnings.warn("No labeled objects found. "
<sympy.plotting.plot.Plot object at 0x3356310>

Looks like matplotlib is not getting the sufficient information from
sympy. If anyone has more insight into this, I would be keen to know.

Thanks.
Amit.
Reply all
Reply to author
Forward
0 new messages