Skip to content

Commit 6ee2de6

Browse files
committed
DOC: Improve Radio Buttons Grid example
Simplify and make more similar with the Radio Buttons example.
1 parent 48a7766 commit 6ee2de6

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

galleries/examples/widgets/radio_buttons_grid.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,32 @@
2323
t = np.arange(0.0, 2.0, 0.01)
2424
s = np.sin(2 * np.pi * t)
2525

26-
fig, (ax_plot, ax_buttons) = plt.subplots(
26+
fig, (ax, ax_buttons) = plt.subplots(
2727
1,
2828
2,
2929
figsize=(8, 4),
3030
width_ratios=[4, 1.4],
3131
)
3232

3333
# Create initial plot
34-
(line,) = ax_plot.plot(t, s, lw=2, color="red")
35-
ax_plot.set_xlabel("Time (s)")
36-
ax_plot.set_ylabel("Amplitude")
37-
ax_plot.set_title("Sine Wave - Click a color!")
38-
ax_plot.grid(True, alpha=0.3)
34+
(line,) = ax.plot(t, s, lw=2, color="red")
35+
ax.set(xlabel="Time (s)", ylabel="Amplitude", title="Sine Wave - Click a color!")
3936

4037
# Configure the radio buttons axes
41-
ax_buttons.set_facecolor("0.9")
42-
ax_buttons.set_title("Line Color", fontsize=12, pad=10)
38+
ax_buttons.set_facecolor("0.95")
39+
ax_buttons.set_title("Line Color")
4340
# Create a 2D grid of color options (3 rows x 2 columns)
4441
colors = ["red", "yellow", "green", "purple", "brown", "gray"]
4542
radio = RadioButtons(ax_buttons, colors, layout=(3, 2))
4643

4744

48-
def color_func(label):
45+
def update_color(label):
4946
"""Update the line color based on selected button."""
5047
line.set_color(label)
5148
fig.canvas.draw()
49+
radio.on_clicked(update_color)
5250

5351

54-
radio.on_clicked(color_func)
55-
5652
plt.show()
5753

5854
# %%

0 commit comments

Comments
 (0)