8000 ENH: Adding zoom and pan to colorbar · matplotlib/matplotlib@1e78220 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e78220

Browse files
committed
ENH: Adding zoom and pan to colorbar
The zoom and pan funcitons change the vmin/vmax of the norm attached to the colorbar. The colorbar is rendered as an inset axis, but the event handler is implemented on the parent axis.
1 parent f2ada0c commit 1e78220

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Colorbars now have pan and zoom functionality
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Interactive plots with colorbars can now be zoomed and panned on
5+
the colorbar axis. This adjusts the *vmin* and *vmax* of the
6+
``ScalarMappable`` associated with the colorbar.

lib/matplotlib/colorbar.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,36 @@ def _short_axis(self):
12741274
return self.ax.xaxis
12751275
return self.ax.yaxis
12761276

1277+
def _get_view(self):
1278+
# docstring inherited
1279+
# An interactive view for a colorbar is the norm's vmin/vmax
1280+
return self.norm.vmin, self.norm.vmax
1281+
1282+
def _set_view(self, view):
1283+
# docstring inherited
1284+
# An interactive view for a colorbar is the norm's vmin/vmax
1285+
self.norm.vmin, self.norm.vmax = view
1286+
1287+
def _set_view_from_bbox(self, bbox, direction='in',
1288+
mode=None, twinx=False, twiny=False):
1289+
# docstring inherited
1290+
# For colorbars, we use the zoom bbox to scale the norm's vmin/vmax
1291+
new_xbound, new_ybound = self.ax._prepare_view_from_bbox(
1292+
bbox, direction=direction, mode=mode, twinx=twinx, twiny=twiny)
1293+
if self.orientation == 'horizontal':
1294+
self.norm.vmin, self.norm.vmax = new_xbound
1295+
elif self.orientation == 'vertical':
1296+
self.norm.vmin, self.norm.vmax = new_ybound
1297+
1298+
def drag_pan(self, button, key, x, y):
1299+
# docstring inherited
1300+
points = self.ax._get_pan_points(button, key, x, y)
1301+
if points is not None:
1302+
if self.orientation == 'horizontal':
1303+
self.norm.vmin, self.norm.vmax = points[:, 0]
1304+
elif self.orientation == 'vertical':
1305+
self.norm.vmin, self.norm.vmax = points[:, 1]
1306+
12771307

12781308
ColorbarBase = Colorbar # Backcompat API
12791309

0 commit comments

Comments
 (0)
0