Matplotlib:如何按标量(浮点数)缩放/乘以 Bbox

要按标量缩放 Bbox 对象,可以使用 Affine2D 变换。以下是具体做法:

scale_bbox.py
# Example scale factor
scale = 300.0

# Create an example bbox
bbox = Bbox.from_bounds(0, 0, 1, 1)

# Create the scale transformation
import matplotlib.transforms as transforms
scale_transform = transforms.Affine2D().scale(scale)

# Example usage
scaled_bbox = bbox.transformed(scale_transform)

Check out similar posts by category: MatPlotLib, Python