646646docstring ._snippet_manager ['axes.legend_kwargs' ] = _legend_kwargs_docstring
647647
648648
649+ def _align_bbox (align , length ):
650+ """
651+ Return a simple alignment bounding box for intersection calculations.
652+ """
653+ if align in ('left' , 'bottom' ):
654+ bounds = [[0 , 0 ], [length , 0 ]]
655+ elif align in ('top' , 'right' ):
656+ bounds = [[1 - length , 0 ], [1 , 0 ]]
657+ elif align == 'center' :
658+ bounds = [[0.5 * (1 - length ), 0 ], [0.5 * (1 + length ), 0 ]]
659+ else :
660+ raise ValueError (f'Invalid align { align !r} .' )
661+ return mtransforms .Bbox (bounds )
662+
663+
649664class _TransformedBoundsLocator :
650665 """
651666 Axes locator for `~Axes.inset_axes` and other axes.
@@ -856,15 +871,6 @@ def _add_guide_panel(self, loc='fill', align='center', length=0, **kwargs):
856871 """
857872 Add a panel to be filled by an "outer" colorbar or legend.
858873 """
859- # Helper function: Return bounds inferred from given align setting.
860- def _align_bbox (align , length ):
861- if align in ('left' , 'bottom' ):
862- bounds = [[0 , 0 ], [length , 0 ]]
863- elif align in ('top' , 'right' ):
864- bounds = [[1 - length , 0 ], [1 , 0 ]]
865- else :
866- bounds = [[0.5 * (1 - length ), 0 ], [0.5 * (1 + length ), 0 ]]
867- return mtransforms .Bbox (bounds )
868874 # NOTE: For colorbars we include 'length' when determining whether to allocate
869875 # new panel but for legend just test whether that 'align' position was filled.
870876 # WARNING: Hide content but 1) do not use ax.set_visible(False) so that
@@ -878,7 +884,7 @@ def _align_bbox(align, length):
878884 for pax in self ._panel_dict [loc ]:
879885 if not pax ._panel_hidden or align in pax ._panel_align :
880886 continue
881- if not any (bbox .overlaps (_align_bbox ( a , l )) for a , l in pax ._panel_align .items ()): # noqa: E501
887+ if not any (bbox .overlaps (b ) for b in pax ._panel_align .values ()):
882888 ax = pax
883889 break
884890 if ax is None :
@@ -891,7 +897,7 @@ def _align_bbox(align, length):
891897 ax .yaxis .set_visible (False )
892898 ax .patch .set_facecolor ('none' )
893899 ax ._panel_hidden = True
894- ax ._panel_align [align ] = length
900+ ax ._panel_align [align ] = bbox
895901 return ax
896902
897903 def _add_inset_axes (
0 commit comments