|
3 | 3 | from matplotlib.backend_bases import ( |
4 | 4 | FigureCanvasBase, LocationEvent, MouseButton, MouseEvent, |
5 | 5 | NavigationToolbar2, RendererBase) |
| 6 | +from matplotlib.backend_tools import (ToolZoom, ToolPan, RubberbandBase, |
| 7 | + ToolViewsPositions, _views_positions) |
6 | 8 | import matplotlib.pyplot as plt |
7 | 9 | import matplotlib.transforms as transforms |
8 | 10 | import matplotlib.path as path |
@@ -157,3 +159,24 @@ def test_interactive_zoom(): |
157 | 159 |
|
158 | 160 | tb.zoom() |
159 | 161 | assert ax.get_navigate_mode() is None |
| 162 | + |
| 163 | + |
| 164 | +def test_toolbar_zoompan(): |
| 165 | + plt.rcParams['toolbar'] = 'toolmanager' |
| 166 | + ax = plt.gca() |
| 167 | + assert ax.get_navigate_mode() is None |
| 168 | + expected_warning_regex = (r"The new Tool classes introduced in " |
| 169 | + r"v[0-9]*.[0-9]* are experimental") |
| 170 | + with pytest.warns(UserWarning, match=expected_warning_regex) as rec: |
| 171 | + ax.figure.canvas.manager.toolmanager.add_tool(name="zoom", |
| 172 | + tool=ToolZoom) |
| 173 | + ax.figure.canvas.manager.toolmanager.add_tool(name="pan", |
| 174 | + tool=ToolPan) |
| 175 | + ax.figure.canvas.manager.toolmanager.add_tool(name=_views_positions, |
| 176 | + tool=ToolViewsPositions) |
| 177 | + ax.figure.canvas.manager.toolmanager.add_tool(name='rubberband', |
| 178 | + tool=RubberbandBase) |
| 179 | + ax.figure.canvas.manager.toolmanager.trigger_tool('zoom') |
| 180 | + assert ax.get_navigate_mode() == "ZOOM" |
| 181 | + ax.figure.canvas.manager.toolmanager.trigger_tool('pan') |
| 182 | + assert ax.get_navigate_mode() == "PAN" |
0 commit comments