Matplotlib:如何平移/偏移 Bbox

要在 Matplotlib 中偏移 Bbox,可以使用 Affine2D 变换。以下是具体做法:

offset_bbox.py
# Example offsets:
x_offset = 0.1
y_offset = 0.5

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

# Create the transform
import matplotlib.transforms as transforms
offset_transform = transforms.Affine2D().translate(x_offset, y_offset)

# Example usage
offset_bbox = bbox.transformed(offset_transform)

Check out similar posts by category: MatPlotLib, Python