MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_interactive_zoom

Function test_interactive_zoom

lib/matplotlib/tests/test_backend_bases.py:165–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

163
164
165def test_interactive_zoom():
166 fig, ax = plt.subplots()
167 ax.set(xscale="logit")
168 assert ax.get_navigate_mode() is None
169
170 tb = NavigationToolbar2(fig.canvas)
171 tb.zoom()
172 assert ax.get_navigate_mode() == 'ZOOM'
173
174 xlim0 = ax.get_xlim()
175 ylim0 = ax.get_ylim()
176
177 # Zoom from x=1e-6, y=0.1 to x=1-1e-5, 0.8 (data coordinates, "d").
178 d0 = (1e-6, 0.1)
179 d1 = (1-1e-5, 0.8)
180 # Convert to screen coordinates ("s"). Events are defined only with pixel
181 # precision, so round the pixel values, and below, check against the
182 # corresponding xdata/ydata, which are close but not equal to d0/d1.
183 s0 = ax.transData.transform(d0).astype(int)
184 s1 = ax.transData.transform(d1).astype(int)
185
186 # Zoom in.
187 start_event = MouseEvent(
188 "button_press_event", fig.canvas, *s0, MouseButton.LEFT)
189 fig.canvas.callbacks.process(start_event.name, start_event)
190 stop_event = MouseEvent(
191 "button_release_event", fig.canvas, *s1, MouseButton.LEFT)
192 fig.canvas.callbacks.process(stop_event.name, stop_event)
193 assert ax.get_xlim() == (start_event.xdata, stop_event.xdata)
194 assert ax.get_ylim() == (start_event.ydata, stop_event.ydata)
195
196 # Zoom out.
197 start_event = MouseEvent(
198 "button_press_event", fig.canvas, *s1, MouseButton.RIGHT)
199 fig.canvas.callbacks.process(start_event.name, start_event)
200 stop_event = MouseEvent(
201 "button_release_event", fig.canvas, *s0, MouseButton.RIGHT)
202 fig.canvas.callbacks.process(stop_event.name, stop_event)
203 # Absolute tolerance much less than original xmin (1e-7).
204 assert ax.get_xlim() == pytest.approx(xlim0, rel=0, abs=1e-10)
205 assert ax.get_ylim() == pytest.approx(ylim0, rel=0, abs=1e-10)
206
207 tb.zoom()
208 assert ax.get_navigate_mode() is None
209
210 assert not ax.get_autoscalex_on() and not ax.get_autoscaley_on()
211
212
213def test_widgetlock_zoompan():

Callers

nothing calls this directly

Calls 10

zoomMethod · 0.95
NavigationToolbar2Class · 0.90
MouseEventClass · 0.90
get_navigate_modeMethod · 0.80
processMethod · 0.80
subplotsMethod · 0.45
setMethod · 0.45
get_xlimMethod · 0.45
get_ylimMethod · 0.45
transformMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…