Retrieve bbox of AnchoredOffsetBox in Matplotlib before rendering

I am trying to retrieve the bbox of an AnchoredOffsetBox in Matplotlib before the canvas itself is rendered. The reason is mostly unimportant, but essentially I want to do this so that I can understand the coordinates the OffsetBox would (hypothetically) exist in, so that I can then change it if it were to meet certain conditions.

For a generic artist, I know I can do the following:

# Create the plot
fig, ax = matplotlib.pyplot.subplots(1,1, figsize=(5,5), dpi=300)
# Create a generic triangle artist at the midpoint of the axis
triangle = ax.add_artist(matplotlib.patches.RegularPolygon((0.5,0.5), 3, radius=0.2))
# Retrieve the bbox of the triangle in data coordinates
ax.transData.inverted().transform(triangle.get_window_extent())

And this same code works if I place the artist in an AnchoredOffsetBox as well, which is useful for more generic positioning code:

# Create the plot
fig, ax = matplotlib.pyplot.subplots(1,1, figsize=(5,5), dpi=300)
# Create a generic triangle artist
triangle = matplotlib.patches.RegularPolygon((0.5,0.5), 3, radius=0.2)
# Create an offsetbox in data coordinates
offsetbox = matplotlib.offsetbox.AuxTransformBox(ax.transData)
# Place the triangle in the offsetbox
offsetbox.add_artist(triangle)
# Place the offsetbox in the AnchoredOffsetBox
container = matplotlib.offsetbox.AnchoredOffsetbox(loc="center", pad=0, child=offsetbox)
# Add the AnchoredOffsetBox to the figure
ax.add_artist(container)
# Retrieve the bbox of the AnchoredOffsetBox in data coordinates
ax.transData.inverted().transform(container.get_window_extent())

(Note: I’m not sure why the triangle rendered with the above code is slightly “lower” than in the first code block, but I’m ignoring this for now)

However, I need to get the position of the AnchoredOffsetBox before it is rendered, so that I can modify its position if necessary. I’ve tried to accomplish it like so:

### SAME AS ABOVE ###
# Create the plot
fig, ax = matplotlib.pyplot.subplots(1,1, figsize=(5,5), dpi=300)
# Create a generic triangle artist
triangle = matplotlib.patches.RegularPolygon((0.5,0.5), 3, radius=0.2)
# Create an offsetbox in data coordinates
offsetbox = matplotlib.offsetbox.AuxTransformBox(ax.transData)
# Place the triangle in the offsetbox
offsetbox.add_artist(triangle)
# Place the offsetbox in the AnchoredOffsetBox
container = matplotlib.offsetbox.AnchoredOffsetbox(loc="center", pad=0, child=offsetbox)
### NEW CODE ###
# Set the figure for the container
container.set_figure(fig)
# Retrieve the renderer for the figure
renderer = fig._get_renderer()
# Retrieve the bbox of the AnchoredOffsetBox in data coordinates
ax.transData.inverted().transform(container.get_bbox(renderer))

Unfortunately, doing this gets me nonsensical results: the data coordinates returned are negative, and I can’t make heads nor tails as to why. My hunch is that get_bbox() does not return the same information as get_window_extent(), but calling get_window_extent() returns AttributeError: 'NoneType' object has no attribute 'bbox'.

If this is an exercise in futility it would be great to know. I am open to any other suggestions as to how I can accomplish a similar feat as well: for some reason I’ve decided it is too difficult to e.g. update the rotation of the artist after it has been added to the axis, but I’ve been working on this problem so long I can’t remember why.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật