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

Function test_range_slider

lib/matplotlib/tests/test_widgets.py:1339–1380  ·  view source on GitHub ↗
(orientation)

Source from the content-addressed store, hash-verified

1337
1338@pytest.mark.parametrize("orientation", ["horizontal", "vertical"])
1339def test_range_slider(orientation):
1340 if orientation == "vertical":
1341 idx = [1, 0, 3, 2]
1342 else:
1343 idx = [0, 1, 2, 3]
1344
1345 fig, ax = plt.subplots()
1346
1347 slider = widgets.RangeSlider(
1348 ax=ax, label="", valmin=0.0, valmax=1.0, orientation=orientation,
1349 valinit=[0.1, 0.34]
1350 )
1351 box = slider.poly.get_extents().transformed(ax.transAxes.inverted())
1352 assert_allclose(box.get_points().flatten()[idx], [0.1, 0.25, 0.34, 0.75])
1353
1354 # Check initial value is set correctly
1355 assert_allclose(slider.val, (0.1, 0.34))
1356
1357 def handle_positions(slider):
1358 if orientation == "vertical":
1359 return [h.get_ydata()[0] for h in slider._handles]
1360 else:
1361 return [h.get_xdata()[0] for h in slider._handles]
1362
1363 slider.set_val((0.4, 0.6))
1364 assert_allclose(slider.val, (0.4, 0.6))
1365 assert_allclose(handle_positions(slider), (0.4, 0.6))
1366
1367 box = slider.poly.get_extents().transformed(ax.transAxes.inverted())
1368 assert_allclose(box.get_points().flatten()[idx], [0.4, .25, 0.6, .75])
1369
1370 slider.set_val((0.2, 0.1))
1371 assert_allclose(slider.val, (0.1, 0.2))
1372 assert_allclose(handle_positions(slider), (0.1, 0.2))
1373
1374 slider.set_val((-1, 10))
1375 assert_allclose(slider.val, (0, 1))
1376 assert_allclose(handle_positions(slider), (0, 1))
1377
1378 slider.reset()
1379 assert_allclose(slider.val, (0.1, 0.34))
1380 assert_allclose(handle_positions(slider), (0.1, 0.34))
1381
1382
1383@pytest.mark.parametrize("orientation", ["horizontal", "vertical"])

Callers

nothing calls this directly

Calls 8

set_valMethod · 0.95
handle_positionsFunction · 0.85
subplotsMethod · 0.45
transformedMethod · 0.45
get_extentsMethod · 0.45
invertedMethod · 0.45
get_pointsMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…