From f8d8a2fa513113c2fa763f01750b7f154b186044 Mon Sep 17 00:00:00 2001 From: Christian Karcher Date: Wed, 18 Mar 2020 12:33:51 +0100 Subject: [PATCH 1/2] legend.py // geographic directions added matlab-like geographic directions as an alternative location string --- lib/matplotlib/legend.py | 44 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index fb47147d152f..d7e48b53f354 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -97,11 +97,13 @@ def _update_bbox_to_anchor(self, loc_in_canvas): The location of the legend. The strings - ``'upper left', 'upper right', 'lower left', 'lower right'`` + ``'upper left', 'upper right', 'lower left', 'lower right', + 'northwest', 'northeast', 'southwest', 'southeast'`` place the legend at the corresponding corner of the axes/figure. The strings - ``'upper center', 'lower center', 'center left', 'center right'`` + ``'upper center', 'lower center', 'center left', 'center right', + 'north', 'south', 'west', 'east'`` place the legend at the center of the corresponding edge of the axes/figure. @@ -120,21 +122,21 @@ def _update_bbox_to_anchor(self, loc_in_canvas): be spelled ``'right'``, and each "string" locations can also be given as a numeric value: - =============== ============= - Location String Location Code - =============== ============= - 'best' 0 - 'upper right' 1 - 'upper left' 2 - 'lower left' 3 - 'lower right' 4 - 'right' 5 - 'center left' 6 - 'center right' 7 - 'lower center' 8 - 'upper center' 9 - 'center' 10 - =============== ============= + ========================== ============= + Location String Location Code + ========================== ============= + 'best' 0 + 'upper right', 'northeast' 1 + 'upper left', 'northwest' 2 + 'lower left', 'southwest' 3 + 'lower right', 'southeast' 4 + 'right' 5 + 'center left', 'west' 6 + 'center right', 'east' 7 + 'lower center', 'south' 8 + 'upper center', 'north' 9 + 'center' 10 + ========================== ============= bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats Box that is used to position the legend in conjunction with *loc*. @@ -266,14 +268,22 @@ class Legend(Artist): """ codes = {'best': 0, # only implemented for axes legends 'upper right': 1, + 'northeast': 1, 'upper left': 2, + 'northwest': 2, 'lower left': 3, + 'southwest': 3, 'lower right': 4, + 'southwest': 4, 'right': 5, 'center left': 6, + 'west': 6, 'center right': 7, + 'east': 7, 'lower center': 8, + 'south': 8, 'upper center': 9, + 'north': 9, 'center': 10, } From 36b8b4da34fd14e1ccd21634d7ac545dcc4a2cdf Mon Sep 17 00:00:00 2001 From: Christian Karcher Date: Wed, 18 Mar 2020 12:43:25 +0100 Subject: [PATCH 2/2] legend.py // typo fixed duplicate southwest location --- lib/matplotlib/legend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index d7e48b53f354..9221e44a66b7 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -274,7 +274,7 @@ class Legend(Artist): 'lower left': 3, 'southwest': 3, 'lower right': 4, - 'southwest': 4, + 'southeast': 4, 'right': 5, 'center left': 6, 'west': 6,