Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e25a898

Browse files
committed
MNT: Updating Colorbar zoom rectangle and selections
Setting the zoom selector rectangle to the vertical/horizontal limits of the colorbar, depending on the orientation. Remove some mappable types from colorbar navigation. Certain mappables, like categoricals and contours shouldn't be mapped by default due to the limits of an axis carrying certain meaning. So, turn that off for now and potentially revisit in the future.
1 parent cbcee5a commit e25a898

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,7 +4418,7 @@ def _get_pan_points(self, button, key, x, y):
44184418
Helper function to return the new points after a pan.
44194419
44204420
This helper function returns the points on the axis after a pan has
4421-
occurred. This a convenience method to abstract the pan logic
4421+
occurred. This is a convenience method to abstract the pan logic
44224422
out of the base setter.
44234423
"""
44244424
def format_deltas(key, dx, dy):
@@ -4475,7 +4475,6 @@ def format_deltas(key, dx, dy):
44754475
points[~valid] = None
44764476
return points
44774477

4478-
44794478
def drag_pan(self, button, key, x, y):
44804479
"""
44814480
Called when the mouse moves during a pan operation.

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,6 +3166,15 @@ def drag_zoom(self, event):
31663166
y1, y2 = ax.bbox.intervaly
31673167
elif event.key == "y":
31683168
x1, x2 = ax.bbox.intervalx
3169+
3170+
# A colorbar is one-dimensional, so we extend the zoom rectangle out
3171+
# to the edge of the axes bbox in the other dimension
3172+
if hasattr(ax, "_colorbar"):
3173+
if ax._colorbar.orientation == 'horizontal':
3174+
y1, y2 = ax.bbox.intervaly
3175+
else:
3176+
x1, x2 = ax.bbox.intervalx
3177+
31693178
self.draw_rubberband(event, x1, y1, x2, y2)
31703179

31713180
def release_zoom(self, event):

lib/matplotlib/colorbar.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ def __init__(self, ax, mappable=None, *, cmap=None,
422422

423423
self.ax = ax
424424
self.ax._axes_locator = _ColorbarAxesLocator(self)
425-
ax.set(navigate=False)
426425

427426
if extend is None:
428427
if (not isinstance(mappable, contour.ContourSet)
@@ -496,6 +495,16 @@ def __init__(self, ax, mappable=None, *, cmap=None,
496495
if isinstance(mappable, contour.ContourSet) and not mappable.filled:
497496
self.add_lines(mappable)
498497

498+
# Link the Axes and Colorbar for interactive use
499+
self.ax._colorbar = self
500+
for x in ["_get_view", "_set_view", "_set_view_from_bbox",
501+
"drag_pan", "start_pan", "end_pan"]:
502+
setattr(self.ax, x, getattr(self, x))
503+
# Don't navigate on any of these types of mappables
504+
if (isinstance(self.norm, (colors.BoundaryNorm, colors.NoNorm)) or
505+
isinstance(self.mappable, contour.ContourSet)):
506+
self.ax.set_navigate(False)
507+
499508
# Also remove ._patch after deprecation elapses.
500509
patch = _api.deprecate_privatize_attribute("3.5", alternative="ax")
501510

0 commit comments

Comments
 (0)