Open
Description
Bug summary
The current implementation seems to assume that the lower left ll
, upper left ul
, and lower right lr
corners are preserved under transformation. This need not be the case. For example, an affine transformation that simply switches coordinates produces a wrong result.
Code for reproduction
import numpy as np
from matplotlib.transforms import Affine2D, Bbox
# Switch 'x' and 'y' coordinates
T = Affine2D(
np.array([
[0,1,0],
[1,0,0],
[0,0,1]
])
)
# Unit vectors
pts = np.array([
[1, 0],
[0, 1]
])
# Produce a Bbox from the unit vectors
bb = Bbox.null()
bb.update_from_data_xy(pts)
# Result
bb.transformed( T )
Actual outcome
In [84]: bb.transformed( T )
Out[84]: Bbox([[0.0, 0.0], [0.0, 0.0]])
Expected outcome
bb.transformed( T ).height == 1.0
bb.transformed( T ).width == 1.0
Additional information
The current implementation (v3.8.0) seems to assume that the lower left ll
, upper left ul
, and lower right lr
corners are preserved under transformation. A more general solution should probably transform each corner and fully recompute the bounding box.
Operating system
linux
Matplotlib Version
3.8.0
Matplotlib Backend
TkAgg
Python version
3.11.5
Jupyter version
No response
Installation
pip