8000 Allow string for offset in an AnchoredOffset · matplotlib/matplotlib@d2ab91a · GitHub
[go: up one dir, main page]

Skip to content

Commit d2ab91a

Browse files
committed
Allow string for offset in an AnchoredOffset
1 parent 54b120f commit d2ab91a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from matplotlib import rcParams
3434

3535
from matplotlib import docstring
36+
from matplotlib.cbook import is_string_like
3637

3738
#from bboximage import BboxImage
3839
from matplotlib.image import BboxImage
@@ -986,6 +987,19 @@ class AnchoredOffsetbox(OffsetBox):
986987
"""
987988
zorder = 5 # zorder of the legend
988989

990+
# Location codes
991+
codes = {'upper right': 1,
992+
'upper left': 2,
993+
'lower left': 3,
994+
'lower right': 4,
995+
'right': 5,
996+
'center left': 6,
997+
'center right': 7,
998+
'lower center': 8,
999+
'upper center': 9,
1000+
'center': 10,
1001+
}
1002+
9891003
def __init__(self, loc,
9901004
pad=0.4, borderpad=0.5,
9911005
child=None, prop=None, frameon=True,
@@ -1028,6 +1042,14 @@ def __init__(self, loc,
10281042
self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)
10291043
self.set_child(child)
10301044

1045+
if is_string_like(loc):
1046+
if loc not in self.codes:
1047+
raise RuntimeError('Unrecognized location "%s". Valid '
1048+
'locations are\n\t%s\n'
1049+
% (loc, '\n\t'.join(self.codes)))
1050+
else:
1051+
loc = self.codes[loc]
1052+
10311053
self.loc = loc
10321054
self.borderpad = borderpad
10331055
self.pad = pad

0 commit comments

Comments
 (0)
0