8000 [BUG]: Button widgets don't work in inset axes · Issue #25030 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[BUG]: Button widgets don't work in inset axes #25030
Closed
@QuLogic

Description

@QuLogic

Summary

If I modify the check button example to put the buttons in an inset axes:

diff --git a/examples/widgets/check_buttons.py b/examples/widgets/check_buttons.py
index 493ac4c3e7..574bad6780 100644
--- a/examples/widgets/check_buttons.py
+++ b/examples/widgets/check_buttons.py
@@ -23,12 +23,11 @@ fig, ax = plt.subplots()
 l0, = ax.plot(t, s0, visible=False, lw=2, color='k', label='2 Hz')
 l1, = ax.plot(t, s1, lw=2, color='r', label='4 Hz')
 l2, = ax.plot(t, s2, lw=2, color='g', label='6 Hz')
-fig.subplots_adjust(left=0.2)
 
 lines_by_label = {l.get_label(): l for l in [l0, l1, l2]}
 
 # Make checkbuttons with all plotted lines with correct visibility
-rax = fig.add_axes([0.05, 0.4, 0.1, 0.15])
+rax = ax.inset_axes([0.0, 0.0, 0.12, 0.2])
 check = CheckButtons(
     ax=rax,
     labels=lines_by_label.keys(),

then the check buttons are not responsive in the inset axes. Clicking on them does nothing.

If I just put them in a regular Axes that happens to overlay the main one, then everything works fine:

diff --git a/examples/widgets/check_buttons.py b/examples/widgets/check_buttons.py
index 493ac4c3e7..574bad6780 100644
--- a/examples/widgets/check_buttons.py
+++ b/examples/widgets/check_buttons.py
@@ -23,12 +23,12 @@ fig, ax = plt.subplots()
 l0, = ax.plot(t, s0, visible=False, lw=2, color='k', label='2 Hz')
 l1, = ax.plot(t, s1, lw=2, color='r', label='4 Hz')
 l2, = ax.plot(t, s2, lw=2, color='g', label='6 Hz')
-fig.subplots_adjust(left=0.2)
 
 lines_by_label = {l.get_label(): l for l in [l0, l1, l2]}
 
 # Make checkbuttons with all plotted lines with correct visibility
-rax = fig.add_axes([0.05, 0.4, 0.1, 0.15])
+bbox = ax.get_position()
+rax = fig.add_axes([bbox.x0, bbox.y0, 0.12, 0.2])
 check = CheckButtons(
     ax=rax,
     labels=lines_by_label.keys(),

Proposed fix

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0