Skip to content

Commit ed91e98

Browse files
committed
FIX: gracefully deal with empty size lists
In HandlerRegularPolyCollection gracefully deal with empty size lists. Fixes matplotlib#4365
1 parent 7285c4c commit ed91e98

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/matplotlib/legend_handler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,11 @@ def get_numpoints(self, legend):
305305
def get_sizes(self, legend, orig_handle,
306306
xdescent, ydescent, width, height, fontsize):
307307
if self._sizes is None:
308-
size_max = max(orig_handle.get_sizes()) * legend.markerscale ** 2
309-
size_min = min(orig_handle.get_sizes()) * legend.markerscale ** 2
308+
handle_sizes = orig_handle.get_sizes()
309+
if not handle_sizes:
310+
handle_sizes = [1]
311+
size_max = max(handle_sizes) * legend.markerscale ** 2
312+
size_min = min(handle_sizes) * legend.markerscale ** 2
310313

311314
numpoints = self.get_numpoints(legend)
312315
if numpoints < 4:

lib/matplotlib/tests/test_legend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ def test_legend_stackplot():
240240
ax.legend(loc=0)
241241

242242

243+
@cleanup
244+
def test_nanscatter():
245+
fig, ax = plt.subplots()
246+
247+
h = ax.scatter([np.nan], [np.nan], marker="o",
248+
facecolor="r", edgecolor="r", s=3)
249+
250+
ax.legend([h], ["scatter"])
251+
252+
243253
if __name__ == '__main__':
244254
import nose
245255
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)