diff --git a/matplotlib_scalebar/scalebar.py b/matplotlib_scalebar/scalebar.py index 92382b1..4b7f51c 100644 --- a/matplotlib_scalebar/scalebar.py +++ b/matplotlib_scalebar/scalebar.py @@ -519,7 +519,7 @@ def _get_value(attr, default): else: child = scale_box - box = AnchoredOffsetbox( + self.box = AnchoredOffsetbox( loc=location, pad=pad, child=child, @@ -529,11 +529,15 @@ def _get_value(attr, default): bbox_transform=self.bbox_transform, ) - box.axes = ax - box.set_figure(self.get_figure()) - box.patch.set_color(box_color) - box.patch.set_alpha(box_alpha) - box.draw(renderer) + self.box.axes = ax + self.box.set_figure(self.get_figure()) + self.box.patch.set_color(box_color) + self.box.patch.set_alpha(box_alpha) + self.box.draw(renderer) + + def get_window_extent(self, renderer): + if hasattr(self, 'box'): + return self.box.get_window_extent(renderer) def get_dx(self): return self._dx