diff --git a/galleries/examples/widgets/check_buttons.py b/galleries/examples/widgets/check_buttons.py index f747d5f52145..0f3b6319028d 100644 --- a/galleries/examples/widgets/check_buttons.py +++ b/galleries/examples/widgets/check_buttons.py @@ -8,6 +8,10 @@ This program shows the use of `.CheckButtons` which is similar to check boxes. There are 3 different sine waves shown, and we can choose which waves are displayed with the check buttons. + +Check buttons may be styled using the *check_props*, *frame_props*, and *label_props* +parameters. The parameters each take a dictionary with keys of artist property names and +values of lists of settings with length matching the number of buttons. """ import matplotlib.pyplot as plt @@ -24,13 +28,12 @@ l0, = ax.plot(t, s0, visible=False, lw=2, color='black', label='1 Hz') l1, = ax.plot(t, s1, lw=2, color='red', label='2 Hz') l2, = ax.plot(t, s2, lw=2, color='green', label='3 Hz') -fig.subplots_adjust(left=0.2) lines_by_label = {l.get_label(): l for l in [l0, l1, l2]} line_colors = [l.get_color() for l in lines_by_label.values()] # 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(), diff --git a/galleries/examples/widgets/radio_buttons.py b/galleries/examples/widgets/radio_buttons.py index 3fdb25bd4e78..b2d7f8396576 100644 --- a/galleries/examples/widgets/radio_buttons.py +++ b/galleries/examples/widgets/radio_buttons.py @@ -8,6 +8,10 @@ Radio buttons let you choose between multiple options in a visualization. In this case, the buttons let the user choose one of the three different sine waves to be shown in the plot. + +Radio buttons may be styled using the *label_props* and *radio_props* parameters, which +each take a dictionary with keys of artist property names and values of lists of +settings with length matching the number of buttons. """ import matplotlib.pyplot as plt @@ -20,13 +24,21 @@ s1 = np.sin(4*np.pi*t) s2 = np.sin(8*np.pi*t) -fig, ax = plt.subplots() -l, = ax.plot(t, s0, lw=2, color='red') -fig.subplots_adjust(left=0.3) - -axcolor = 'lightgoldenrodyellow' -rax = fig.add_axes([0.05, 0.7, 0.15, 0.15], facecolor=axcolor) -radio = RadioButtons(rax, ('1 Hz', '2 Hz', '4 Hz'), +fig, ax = plt.subplot_mosaic( + [ + ['main', 'freq'], + ['main', 'color'], + ['main', 'linestyle'], + ], + width_ratios=[5, 1], + layout='constrained', +) +l, = ax['main'].plot(t, s0, lw=2, color='red') + +radio_background = 'lightgoldenrodyellow' + +ax['freq'].set_facecolor(radio_background) +radio = RadioButtons(ax['freq'], ('1 Hz', '2 Hz', '4 Hz'), label_props={'color': 'cmy', 'fontsize': [12, 14, 16]}, radio_props={'s': [16, 32, 64]}) @@ -38,9 +50,9 @@ def hzfunc(label): fig.canvas.draw() radio.on_clicked(hzfunc) -rax = fig.add_axes([0.05, 0.4, 0.15, 0.15], facecolor=axcolor) +ax['color'].set_facecolor(radio_background) radio2 = RadioButtons( - rax, ('red', 'blue', 'green'), + ax['color'], ('red', 'blue', 'green'), label_props={'color': ['red', 'blue', 'green']}, radio_props={ 'facecolor': ['red', 'blue', 'green'], @@ -53,8 +65,8 @@ def colorfunc(label): fig.canvas.draw() radio2.on_clicked(colorfunc) -rax = fig.add_axes([0.05, 0.1, 0.15, 0.15], facecolor=axcolor) -radio3 = RadioButtons(rax, ('-', '--', '-.', ':')) +ax['linestyle'].set_facecolor(radio_background) +radio3 = RadioButtons(ax['linestyle'], ('-', '--', '-.', ':')) def stylefunc(label):