Skip to content

axes has no method to return new position after box is adjusted due to aspect ratio... #9207

@jklymak

Description

@jklymak

Bug report

Bug summary

axes has no method to return new position after box is adjusted due to aspect ratio...

Code for reproduction

fig, ax = plt.subplots(figsize=(2,4))
print(ax.get_position())
ax.set_aspect(1.)
print(ax.get_position(original=False))

Actual outcome

Bbox(x0=0.125, y0=0.10999999999999999, x1=0.9, y1=0.88)
Bbox(x0=0.125, y0=0.10999999999999999, x1=0.9, y1=0.88)

Expected/Desired outcome

Bbox(x0=0.125, y0=0.10999999999999999, x1=0.9, y1=0.88)
Bbox(x0=0.125, y0=0.30125, x1=0.9, y1=0.68875)

Source of issue

axes.get_position() is pretty simple, but always returns the frozen version of the axes position...

    def get_position(self, original=False):
        'Return the a copy of the axes rectangle as a Bbox'
        if original:
            return self._originalPosition.frozen()
        else:
            return self._position.frozen()

However, in axes.apply_aspect() this code is executed that changes the box size:

        figW, figH = self.get_figure().get_size_inches()
        fig_aspect = figH / figW
        if self._adjustable in ['box', 'box-forced']:
            if aspect_scale_mode == "log":
                box_aspect = A * self.get_data_ratio_log()
            else:
                box_aspect = A * self.get_data_ratio()
            pb = position.frozen()
            pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
            self.set_position(pb1.anchored(self.get_anchor(), pb), 'active')
            return

It would be nice if we could somehow get at the new bbox:

    pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
    pb1 = pb1.anchored(self.get_anchor(), pb)

I don't understand why in both cases the frozen position is returned in ax.get_position() rather than the current position. But maybe a new method get_adjusted_position() would work if we don't want to change get_position()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions