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