Skip to content

Commit a94ecc5

Browse files
committed
Legend: Include reverse parameter and if cond
1 parent 1d13d2d commit a94ecc5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/legend.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def __init__(
312312
numpoints=None, # number of points in the legend line
313313
markerscale=None, # relative size of legend markers vs. original
314314
markerfirst=True, # left/right ordering of legend marker and label
315+
reverse=False # reverse ordering of legend marker and label
315316
scatterpoints=None, # number of scatter points
316317
scatteryoffsets=None,
317318
prop=None, # properties for the legend texts
@@ -525,7 +526,7 @@ def val_or_rc(val, rc_name):
525526
self._alignment = alignment
526527

527528
# init with null renderer
528-
self._init_legend_box(handles, labels, markerfirst)
529+
self._init_legend_box(handles, labels, markerfirst, reverse)
529530

530531
tmp = self._loc_used_default
531532
self._set_loc(loc)
@@ -750,7 +751,7 @@ def get_legend_handler(legend_handler_map, orig_handle):
750751
pass
751752
return None
752753

753-
def _init_legend_box(self, handles, labels, markerfirst=True):
754+
def _init_legend_box(self, handles, labels, markerfirst=True, reverse=False):
754755
"""
755756
Initialize the legend_box. The legend_box is an instance of
756757
the OffsetBox, which is packed with legend handles and
@@ -783,6 +784,9 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
783784
# default transform (e.g., Collections), you need to
784785
# manually set their transform to the self.get_transform().
785786
legend_handler_map = self.get_legend_handler_map()
787+
if reverse == True:
788+
handles.reverse()
789+
labels.reverse()
786790

787791
for orig_handle, label in zip(handles, labels):
788792
handler = self.get_legend_handler(legend_handler_map, orig_handle)

0 commit comments

Comments
 (0)