8000 Allow BboxBase.padded to accept a tuple or list · EzraBC/matplotlib@ad9ec99 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad9ec99

Browse files
authored
Allow BboxBase.padded to accept a tuple or list
In addition to allowing a dict, added support for a tuple or list being passed. Also fixed some indentation and changed the dict keys to those mentioned in issue matplotlib#11764
1 parent f51ab56 commit ad9ec99

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/matplotlib/transforms.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,17 @@ def padded(self, p):
690690
"""
691691
Return a new :class:`Bbox` that is padded on all four sides by
692692
the given values. The parameter p can be a dict with keys
693-
['west', 'south', 'east', 'north'] or a single value.
693+
['left', 'right', 'bottom', 'top'], a tuple or list in the same
694+
order, or a single value.
694695
"""
696+
keys = ['left', 'right', 'bottom', 'top']
695697
if not isinstance(p, dict):
696-
p = dict.fromkeys(('west', 'south', 'east', 'north'), p)
698+
if any(isinstance(p, t) for t in (tuple, list)):
699+
p = dict(zip(keys, p))
700+
else:
701+
p = dict.fromkeys(keys, p)
697702
points = self.get_points()
698-
return Bbox(points + [[-p['west'], -p['south']], [p['east'], p['north']]])
703+
return Bbox(points + [[-p['left'], -p['bottom']], [p['right'], p['top']]])
699704

700705
def translated(self, tx, ty):
701706
"""

0 commit comments

Comments
 (0)
0