|
33 | 33 |
|
34 | 34 | from matplotlib import rcParams
|
35 | 35 | from matplotlib.artist import Artist, allow_rasterization
|
36 |
| -from matplotlib.cbook import (is_string_like, iterable, silent_list, safezip) |
| 36 | +from matplotlib.cbook import (is_string_like, iterable, silent_list, safezip, |
| 37 | + is_hashable) |
37 | 38 | from matplotlib.font_manager import FontProperties
|
38 | 39 | from matplotlib.lines import Line2D
|
39 | 40 | from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch
|
@@ -565,19 +566,19 @@ def get_legend_handler(legend_handler_map, orig_handle):
|
565 | 566 | method-resolution-order. If no matching key is found, it
|
566 | 567 | returns None.
|
567 | 568 | """
|
568 |
| - legend_handler_keys = list(six.iterkeys(legend_handler_map)) |
569 |
| - if orig_handle in legend_handler_keys: |
570 |
| - handler = legend_handler_map[orig_handle] |
571 |
| - else: |
| 569 | + if is_hashable(orig_handle): |
| 570 | + try: |
| 571 | + return legend_handler_map[orig_handle] |
| 572 | + except KeyError: |
| 573 | + pass |
572 | 574 |
|
573 |
| - for handle_type in type(orig_handle).mro(): |
574 |
| - if handle_type in legend_handler_map: |
575 |
| - handler = legend_handler_map[handle_type] |
576 |
| - break |
577 |
| - else: |
578 |
| - handler = None |
| 575 | + for handle_type in type(orig_handle).mro(): |
| 576 | + try: |
| 577 | + return legend_handler_map[handle_type] |
| 578 | + except KeyError: |
| 579 | + pass |
579 | 580 |
|
580 |
| - return handler |
| 581 | + return None |
581 | 582 |
|
582 | 583 | def _init_legend_box(self, handles, labels, markerfirst=True):
|
583 | 584 | """
|
|
0 commit comments