Skip to content

Commit ddf6d95

Browse files
committed
Add a dpi transform to AuxTransformBox
**Issue** While the children themselves (e.g. Text objects) to an AuxTransformBox do conform to the dpi of the figure, the locations of the objects do not. Therefore the space taken up by the AuxTransformBox remains just about fixed, regardless of dpi. The relative distance between any two objects in the AuxTransformBox remains absolutely fixed. This leads to "scaling" artefacts for *png* output when the dpi is not 72. **Solution** Add a similar dpi transformation to that done for the DrawingArea.
1 parent 23afcb4 commit ddf6d95

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,8 @@ def __init__(self, aux_transform):
898898
self.ref_offset_transform = mtransforms.Affine2D()
899899
self.ref_offset_transform.clear()
900900

901+
self.dpi_transform = mtransforms.Affine2D()
902+
901903
def add_artist(self, a):
902904
'Add any :class:`~matplotlib.artist.Artist` to the container box'
903905
self._children.append(a)
@@ -911,6 +913,7 @@ def get_transform(self):
911913
"""
912914
return self.aux_transform + \
913915
self.ref_offset_transform + \
916+
self.dpi_transform + \
914917
self.offset_transform
915918

916919
def set_transform(self, t):
@@ -963,13 +966,18 @@ def get_extent(self, renderer):
963966
mtx = self.offset_transform.matrix_from_values(*_off)
964967
self.offset_transform.set_matrix(mtx)
965968

966-
return ub.width, ub.height, 0., 0.
969+
dpi_cor = renderer.points_to_pixels(1.)
970+
return ub.width*dpi_cor, ub.height*dpi_cor, 0., 0.
967971

968972
def draw(self, renderer):
969973
"""
970974
Draw the children
971975
"""
972976

977+
dpi_cor = renderer.points_to_pixels(1.)
978+
self.dpi_transform.clear()
979+
self.dpi_transform.scale(dpi_cor, dpi_cor)
980+
973981
for c in self._children:
974982
c.draw(renderer)
975983

0 commit comments

Comments
 (0)