Place the colorbar in its new place. Parameters ---------- layoutgrids : dict cbax : `~matplotlib.axes.Axes` Axes for the colorbar. renderer : `~matplotlib.backend_bases.RendererBase` subclass. The renderer to use. offset : array-like Offset the
(layoutgrids, cbax, renderer, *, offset=None, compress=False)
| 685 | |
| 686 | |
| 687 | def reposition_colorbar(layoutgrids, cbax, renderer, *, offset=None, compress=False): |
| 688 | """ |
| 689 | Place the colorbar in its new place. |
| 690 | |
| 691 | Parameters |
| 692 | ---------- |
| 693 | layoutgrids : dict |
| 694 | cbax : `~matplotlib.axes.Axes` |
| 695 | Axes for the colorbar. |
| 696 | renderer : `~matplotlib.backend_bases.RendererBase` subclass. |
| 697 | The renderer to use. |
| 698 | offset : array-like |
| 699 | Offset the colorbar needs to be pushed to in order to |
| 700 | account for multiple colorbars. |
| 701 | compress : bool |
| 702 | Whether we're in compressed layout mode. |
| 703 | """ |
| 704 | |
| 705 | parents = cbax._colorbar_info['parents'] |
| 706 | gs = parents[0].get_gridspec() |
| 707 | fig = cbax.get_figure(root=False) |
| 708 | trans_fig_to_subfig = fig.transFigure - fig.transSubfigure |
| 709 | |
| 710 | cb_rspans, cb_cspans = get_cb_parent_spans(cbax) |
| 711 | bboxparent = layoutgrids[gs].get_bbox_for_cb(rows=cb_rspans, |
| 712 | cols=cb_cspans) |
| 713 | pb = layoutgrids[gs].get_inner_bbox(rows=cb_rspans, cols=cb_cspans) |
| 714 | |
| 715 | location = cbax._colorbar_info['location'] |
| 716 | anchor = cbax._colorbar_info['anchor'] |
| 717 | fraction = cbax._colorbar_info['fraction'] |
| 718 | aspect = cbax._colorbar_info['aspect'] |
| 719 | shrink = cbax._colorbar_info['shrink'] |
| 720 | |
| 721 | # For colorbars with a single parent in compressed layout, |
| 722 | # use the actual visual size of the parent axis after apply_aspect() |
| 723 | # has been called. This ensures colorbars align with their parent axes. |
| 724 | # This fix is specific to single-parent colorbars where alignment is critical. |
| 725 | if compress and len(parents) == 1: |
| 726 | from matplotlib.transforms import Bbox |
| 727 | # Get the actual parent position after apply_aspect() |
| 728 | parent_ax = parents[0] |
| 729 | actual_pos = parent_ax.get_position(original=False) |
| 730 | # Transform to figure coordinates |
| 731 | actual_pos_fig = actual_pos.transformed(fig.transSubfigure - fig.transFigure) |
| 732 | |
| 733 | if location in ('left', 'right'): |
| 734 | # For vertical colorbars, use the actual parent bbox height |
| 735 | # for colorbar sizing |
| 736 | # Keep the pb x-coordinates but use actual y-coordinates |
| 737 | pb = Bbox.from_extents(pb.x0, actual_pos_fig.y0, |
| 738 | pb.x1, actual_pos_fig.y1) |
| 739 | elif location in ('top', 'bottom'): |
| 740 | # For horizontal colorbars, use the actual parent bbox width |
| 741 | # for colorbar sizing |
| 742 | # Keep the pb y-coordinates but use actual x-coordinates |
| 743 | pb = Bbox.from_extents(actual_pos_fig.x0, pb.y0, |
| 744 | actual_pos_fig.x1, pb.y1) |
no test coverage detected
searching dependent graphs…