Skip to content

[BUG]: Button widgets don't work in inset axes #25030

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy