Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ed91e98

Browse filesBrowse files
committed
FIX: gracefully deal with empty size lists
In HandlerRegularPolyCollection gracefully deal with empty size lists. Fixes #4365
1 parent 7285c4c commit ed91e98
Copy full SHA for ed91e98

File tree

Expand file treeCollapse file tree

2 files changed

+15
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-2
lines changed

‎lib/matplotlib/legend_handler.py

Copy file name to clipboardExpand all lines: lib/matplotlib/legend_handler.py
+5-2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_legend.py
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.