Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7bf8db3

Browse filesBrowse files
authored
Merge pull request #15071 from anntzer/offsetbox
Cleanup offsetbox.py.
2 parents ddd23a8 + b07c544 commit 7bf8db3
Copy full SHA for 7bf8db3

File tree

Expand file treeCollapse file tree

1 file changed

+11
-42
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-42
lines changed
Open diff view settings
Collapse file

‎lib/matplotlib/offsetbox.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/offsetbox.py
+11-42Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,9 @@ def get_extent_offsets(self, renderer):
608608
# docstring inherited.
609609
dpicor = renderer.points_to_pixels(1.)
610610
pad = self.pad * dpicor
611-
612611
w, h, xd, yd = self._children[0].get_extent(renderer)
613-
614-
return w + 2 * pad, h + 2 * pad, \
615-
xd + pad, yd + pad, \
616-
[(0, 0)]
612+
return (w + 2 * pad, h + 2 * pad, xd + pad, yd + pad,
613+
[(0, 0)])
617614

618615
def draw(self, renderer):
619616
"""
@@ -668,19 +665,13 @@ def __init__(self, width, height, xdescent=0.,
668665
*xdescent*, *ydescent* : descent of the box in x- and y-direction.
669666
*clip* : Whether to clip the children
670667
"""
671-
672668
super().__init__()
673-
674669
self.width = width
675670
self.height = height
676671
self.xdescent = xdescent
677672
self.ydescent = ydescent
678673
self._clip_children = clip
679-
680674
self.offset_transform = mtransforms.Affine2D()
681-
self.offset_transform.clear()
682-
self.offset_transform.translate(0, 0)
683-
684675
self.dpi_transform = mtransforms.Affine2D()
685676

686677
@property
@@ -698,16 +689,14 @@ def clip_children(self, val):
698689

699690
def get_transform(self):
700691
"""
701-
Return the :class:`~matplotlib.transforms.Transform` applied
702-
to the children
692+
Return the `~matplotlib.transforms.Transform` applied to the children.
703693
"""
704694
return self.dpi_transform + self.offset_transform
705695

706696
def set_transform(self, t):
707697
"""
708698
set_transform is ignored.
709699
"""
710-
pass
711700

712701
def set_offset(self, xy):
713702
"""
@@ -719,7 +708,6 @@ def set_offset(self, xy):
719708
The (x, y) coordinates of the offset in display units.
720709
"""
721710
self._offset = xy
722-
723711
self.offset_transform.clear()
724712
self.offset_transform.translate(xy[0], xy[1])
725713
self.stale = True
@@ -745,8 +733,8 @@ def get_extent(self, renderer):
745733
"""
746734

747735
dpi_cor = renderer.points_to_pixels(1.)
748-
return self.width * dpi_cor, self.height * dpi_cor, \
749-
self.xdescent * dpi_cor, self.ydescent * dpi_cor
736+
return (self.width * dpi_cor, self.height * dpi_cor,
737+
self.xdescent * dpi_cor, self.ydescent * dpi_cor)
750738

751739
def add_artist(self, a):
752740
'Add any :class:`~matplotlib.artist.Artist` to the container box'
@@ -816,23 +804,14 @@ def __init__(self, s,
816804
"""
817805
if textprops is None:
818806
textprops = {}
819-
820-
if "va" not in textprops:
821-
textprops["va"] = "baseline"
822-
807+
textprops.setdefault("va", "baseline")
823808
self._text = mtext.Text(0, 0, s, **textprops)
824-
825809
OffsetBox.__init__(self)
826-
827810
self._children = [self._text]
828-
829811
self.offset_transform = mtransforms.Affine2D()
830-
self.offset_transform.clear()
831-
self.offset_transform.translate(0, 0)
832812
self._baseline_transform = mtransforms.Affine2D()
833813
self._text.set_transform(self.offset_transform +
834814
self._baseline_transform)
835-
836815
self._multilinebaseline = multilinebaseline
837816
self._minimumdescent = minimumdescent
838817

@@ -881,7 +860,6 @@ def set_transform(self, t):
881860
"""
882861
set_transform is ignored.
883862
"""
884-
pass
885863

886864
def set_offset(self, xy):
887865
"""
@@ -893,7 +871,6 @@ def set_offset(self, xy):
893871
The (x, y) coordinates of the offset in display units.
894872
"""
895873
self._offset = xy
896-
897874
self.offset_transform.clear()
898875
self.offset_transform.translate(xy[0], xy[1])
899876
self.stale = True
@@ -969,16 +946,10 @@ class AuxTransformBox(OffsetBox):
969946
def __init__(self, aux_transform):
970947
self.aux_transform = aux_transform
971948
OffsetBox.__init__(self)
972-
973949
self.offset_transform = mtransforms.Affine2D()
974-
self.offset_transform.clear()
975-
self.offset_transform.translate(0, 0)
976-
977-
# ref_offset_transform is used to make the offset_transform is
978-
# always reference to the lower-left corner of the bbox of its
979-
# children.
950+
# ref_offset_transform makes offset_transform always relative to the
951+
# lower-left corner of the bbox of its children.
980952
self.ref_offset_transform = mtransforms.Affine2D()
981-
self.ref_offset_transform.clear()
982953

983954
def add_artist(self, a):
984955
'Add any :class:`~matplotlib.artist.Artist` to the container box'
@@ -991,15 +962,14 @@ def get_transform(self):
991962
Return the :class:`~matplotlib.transforms.Transform` applied
992963
to the children
993964
"""
994-
return self.aux_transform + \
995-
self.ref_offset_transform + \
996-
self.offset_transform
965+
return (self.aux_transform
966+
+ self.ref_offset_transform
967+
+ self.offset_transform)
997968

998969
def set_transform(self, t):
999970
"""
1000971
set_transform is ignored.
1001972
"""
1002-
pass
1003973

1004974
def set_offset(self, xy):
1005975
"""
@@ -1011,7 +981,6 @@ def set_offset(self, xy):
1011981
The (x, y) coordinates of the offset in display units.
1012982
"""
1013983
self._offset = xy
1014-
1015984
self.offset_transform.clear()
1016985
self.offset_transform.translate(xy[0], xy[1])
1017986
self.stale = True

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.