Skip to content

Commit 5394aff

Browse files
minor re-formatting and standardization of variable names
Co-authored-by: Elliott Sales de Andrade <[email protected]>
1 parent af3a97e commit 5394aff

File tree

3 files changed

+24
-37
lines changed

3 files changed

+24
-37
lines changed

galleries/examples/showcase/pan_zoom_overlap.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,30 @@
3232

3333
import matplotlib.pyplot as plt
3434

35-
f = plt.figure(figsize=(11, 6))
36-
f.suptitle("Showcase for pan/zoom events on overlapping axes.")
35+
fig = plt.figure(figsize=(11, 6))
36+
fig.suptitle("Showcase for pan/zoom events on overlapping axes.")
3737

38-
ax = f.add_axes((.05, .05, .9, .9))
38+
ax = fig.add_axes((.05, .05, .9, .9))
3939
ax.patch.set_color(".75")
4040
ax_twin = ax.twinx()
4141

42-
ax1 = f.add_subplot(221)
42+
ax1 = fig.add_subplot(221)
4343
ax1_twin = ax1.twinx()
4444
ax1.text(.5, .5,
4545
"Visible patch\n\n"
4646
"Pan/zoom events are NOT\n"
4747
"forwarded to axes below",
4848
ha="center", va="center", transform=ax1.transAxes)
4949

50-
ax11 = f.add_subplot(223, sharex=ax1, sharey=ax1)
50+
ax11 = fig.add_subplot(223, sharex=ax1, sharey=ax1)
5151
ax11.set_forward_navigation_events(True)
5252
ax11.text(.5, .5,
5353
"Visible patch\n\n"
5454
"Override capture behavior:\n\n"
5555
"ax.set_forward_navigation_events(True)",
5656
ha="center", va="center", transform=ax11.transAxes)
5757

58-
ax2 = f.add_subplot(222)
58+
ax2 = fig.add_subplot(222)
5959
ax2_twin = ax2.twinx()
6060
ax2.patch.set_visible(False)
6161
ax2.text(.5, .5,
@@ -64,7 +64,7 @@
6464
"forwarded to axes below",
6565
ha="center", va="center", transform=ax2.transAxes)
6666

67-
ax22 = f.add_subplot(224, sharex=ax2, sharey=ax2)
67+
ax22 = fig.add_subplot(224, sharex=ax2, sharey=ax2)
6868
ax22.patch.set_visible(False)
6969
ax22.set_forward_navigation_events(False)
7070
ax22.text(.5, .5,

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,7 @@ def _zoom_pan_handler(self, event):
29952995
elif event.name == "button_release_event":
29962996
self.release_zoom(event)
29972997

2998-
def _start_event_axes_interaction(self, event, method="zoom"):
2998+
def _start_event_axes_interaction(self, event, *, method):
29992999

30003000
def _ax_filter(ax):
30013001
return (ax.in_axes(event) and

lib/matplotlib/tests/test_backend_bases.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ def test_toolmanager_update_keymap():
446446
@pytest.mark.parametrize("patch_vis", [True, False])
447447
@pytest.mark.parametrize("forward_nav", [True, False, "auto"])
448448
@pytest.mark.parametrize("t_s", ["twin", "share"])
449-
def test_interactive_pan_zoom_events(tool, button, patch_vis,
450-
forward_nav, t_s):
449+
def test_interactive_pan_zoom_events(tool, button, patch_vis, forward_nav, t_s):
451450
# Bottom axes: ax_b Top axes: ax_t
452451
fig, ax_b = plt.subplots()
453452
ax_t = fig.add_subplot(221, zorder=99)
@@ -492,7 +491,7 @@ def test_interactive_pan_zoom_events(tool, button, patch_vis,
492491
xstart_t, xstop_t, ystart_t, ystop_t = 1, 2, 1, 2
493492
# Convert to screen coordinates ("s"). Events are defined only with pixel
494493
# precision, so round the pixel values, and below, check against the
495-
# corresponding xdata/ydata, which are close but not equal to d0/d1.
494+
# corresponding xdata/ydata, which are close but not equal to s0/s1.
496495
s0 = ax_t.transData.transform((xstart_t, ystart_t)).astype(int)
497496
s1 = ax_t.transData.transform((xstop_t, ystop_t)).astype(int)
498497

@@ -501,30 +500,25 @@ def test_interactive_pan_zoom_events(tool, button, patch_vis,
501500
xstop_b, ystop_b = ax_b.transData.inverted().transform(s1)
502501

503502
# Set up the mouse movements
504-
start_event = MouseEvent(
505-
"button_press_event", fig.canvas, *s0, button)
506-
stop_event = MouseEvent(
507-
"button_release_event", fig.canvas, *s1, button)
503+
start_event = MouseEvent("button_press_event", fig.canvas, *s0, button)
504+
stop_event = MouseEvent("button_release_event", fig.canvas, *s1, button)
508505

509506
tb = NavigationToolbar2(fig.canvas)
510507

511508
if tool == "zoom":
512509
# Evaluate expected limits before executing the zoom-event
513510
direction = ("in" if button == 1 else "out")
514511

515-
xlim_t, ylim_t = ax_t._prepare_view_from_bbox(
516-
[*s0, *s1], direction)
512+
xlim_t, ylim_t = ax_t._prepare_view_from_bbox([*s0, *s1], direction)
517513

518514
if ax_t.get_forward_navigation_events() is True:
519-
xlim_b, ylim_b = ax_b._prepare_view_from_bbox(
520-
[*s0, *s1], direction)
515+
xlim_b, ylim_b = ax_b._prepare_view_from_bbox([*s0, *s1], direction)
521516
elif ax_t.get_forward_navigation_events() is False:
522517
xlim_b = init_xlim
523518
ylim_b = init_ylim
524519
else:
525-
if ax_t.patch.get_visible() is False:
526-
xlim_b, ylim_b = ax_b._prepare_view_from_bbox(
527-
[*s0, *s1], direction)
520+
if not ax_t.patch.get_visible():
521+
xlim_b, ylim_b = ax_b._prepare_view_from_bbox([*s0, *s1], direction)
528522
else:
529523
xlim_b = init_xlim
530524
ylim_b = init_ylim
@@ -540,31 +534,26 @@ def test_interactive_pan_zoom_events(tool, button, patch_vis,
540534
assert ax_b.get_ylim() == pytest.approx(ylim_b, abs=0.15)
541535

542536
# Check if twin-axes are properly triggered
543-
assert ax_t.get_xlim() == pytest.approx(ax_t_twin.get_xlim(),
544-
abs=0.15)
545-
assert ax_b.get_xlim() == pytest.approx(ax_b_twin.get_xlim(),
546-
abs=0.15)
537+
assert ax_t.get_xlim() == pytest.approx(ax_t_twin.get_xlim(), abs=0.15)
538+
assert ax_b.get_xlim() == pytest.approx(ax_b_twin.get_xlim(), abs=0.15)
547539
else:
548540
# Evaluate expected limits
549541
# (call start_pan to make sure ax._pan_start is set)
550542
ax_t.start_pan(*s0, button)
551-
xlim_t, ylim_t = ax_t._get_pan_points(
552-
button, None, *s1).T.astype(float)
543+
xlim_t, ylim_t = ax_t._get_pan_points(button, None, *s1).T.astype(float)
553544
ax_t.end_pan()
554545

555546
if ax_t.get_forward_navigation_events() is True:
556547
ax_b.start_pan(*s0, button)
557-
xlim_b, ylim_b = ax_b._get_pan_points(
558-
button, None, *s1).T.astype(float)
548+
xlim_b, ylim_b = ax_b._get_pan_points(button, None, *s1).T.astype(float)
559549
ax_b.end_pan()
560550
elif ax_t.get_forward_navigation_events() is False:
561551
xlim_b = init_xlim
562552
ylim_b = init_ylim
563553
else:
564-
if ax_t.patch.get_visible() is False:
554+
if not ax_t.patch.get_visible():
565555
ax_b.start_pan(*s0, button)
566-
xlim_b, ylim_b = ax_b._get_pan_points(
567-
button, None, *s1).T.astype(float)
556+
xlim_b, ylim_b = ax_b._get_pan_points(button, None, *s1).T.astype(float)
568557
ax_b.end_pan()
569558
else:
570559
xlim_b = init_xlim
@@ -581,7 +570,5 @@ def test_interactive_pan_zoom_events(tool, button, patch_vis,
581570
assert ax_b.get_ylim() == pytest.approx(ylim_b, abs=0.15)
582571

583572
# Check if twin-axes are properly triggered
584-
assert ax_t.get_xlim() == pytest.approx(ax_t_twin.get_xlim(),
585-
abs=0.15)
586-
assert ax_b.get_xlim() == pytest.approx(ax_b_twin.get_xlim(),
587-
abs=0.15)
573+
assert ax_t.get_xlim() == pytest.approx(ax_t_twin.get_xlim(), abs=0.15)
574+
assert ax_b.get_xlim() == pytest.approx(ax_b_twin.get_xlim(), abs=0.15)

0 commit comments

Comments
 (0)