Skip to content

Commit b574177

Browse files
committed
Redo colorbar overhaul.
Previous overhaul packaged an inner and outer axes in a container "ColorbarAxes" and tried to dispatch methods between them. This overhaul takes the _much_ simpler approach of resizing the image using a custom _axes_locator that a) calls any existing locator b) or just uses the axes default position. The custom _axes_locator then shrinks the axes in the appropriate direction to make room for extend tri/rectangles. As with the previous fix, the extend tri/rectangles are drawn as patches in axes co-ordinates, rather than pcolormesh in "data" co-ordinates.
1 parent 8c764dc commit b574177

File tree

14 files changed

+567
-561
lines changed

14 files changed

+567
-561
lines changed

doc/api/next_api_changes/behavior/20054-JMK.rst

-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
Axes used to make colorbar now wrapped
2-
======================================
3-
4-
The axes used to place a colorbar is now wrapped by a new parent class
5-
(``ColorbarAxes``) when the colorbar is created::
6-
7-
cb = fig.colorbar(im, cax=cax)
8-
9-
This means that ``cb.ax`` is no longer the same object as ``cax``. However,
10-
we map all the methods from ``cb.ax`` onto ``cax`` so ``cax`` should remain
11-
functionally the same as ``cb.ax``.
12-
131
Colorbar lines no longer clipped
142
================================
153

lib/matplotlib/_constrained_layout.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,11 @@ def _reposition_colorbar(cbax, renderer, *, offset=None):
575575
pbcb = trans_fig_to_subfig.transform_bbox(pbcb)
576576
cbax.set_transform(fig.transSubfigure)
577577
cbax._set_position(pbcb)
578-
cbax.set_aspect(aspect, anchor=anchor, adjustable='box')
578+
cbax.set_anchor(anchor)
579+
if location in ['bottom', 'top']:
580+
aspect = 1 / aspect
581+
cbax.set_box_aspect(aspect)
582+
cbax.set_aspect('auto')
579583
return offset
580584

581585

lib/matplotlib/axes/_base.py

+2
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,8 @@ def _update_patch_limits(self, patch):
23802380
return
23812381
patch_trf = patch.get_transform()
23822382
updatex, updatey = patch_trf.contains_branch_seperately(self.transData)
2383+
if not (updatex or updatey):
2384+
return
23832385
if self.name != "rectilinear":
23842386
# As in _update_line_limits, but for axvspan.
23852387
if updatex and patch_trf == self.get_yaxis_transform():

0 commit comments

Comments
 (0)