Repository: matplotlib/matplotlib
File: lib/matplotlib/widgets.py (Python)

Code before:

    # Center rows vertically in the axes
    ys_per_row = np.linspace(1, 0, n_rows + 2)[1:-1]
    # Calculate x positions based on text widths
    col_x_positions = [left_margin]  # First column starts at left margin
    for col_idx in range(n_cols - 1):
        col_x_positions.append(
            col_x_positions[-1] +
            button_text_offset +
            col_widths[col_idx] +
            col_spacing
        )
    # Create final positions (left-to-right, top-to-bottom)
    button_xs = []
    button_ys = []
    label_xs = []
    label_ys = []
    for label_idx in range(n_labels):
        row_idx = label_idx // n_cols
        col_idx = label_idx % n_cols
        x = col_x_positions[col_idx]
        y = ys_per_row[row_idx]
        button_xs.append(x)
        button_ys.append(y)
        label_xs.append(x + button_text_offset)
        label_ys.append(y)

    return button_xs, button_ys, label_xs, label_ys


class RadioButtons(AxesWidget):
    """
    A GUI neutral radio button.

    For the buttons to remain responsive you must keep a reference to this
    object.

    Connect to the RadioButtons with the `.on_clicked` method.

    Attributes
    ----------
    ax : `~matplotlib.axes.Axes`
        The parent Axes for the widget.
    activecolor : :mpltype:`color`
        The color of the selected button.
    labels : list of `.Text`
        The button labels.
    value_selected : str
        The label text of the currently selected button.
    index_selected : int
        The index of the selected button.

Review comment (suggestion):
```suggestion
    label_idx = np.arange(n_labels)
    button_xs = np.take(col_x_positions, label_idx % n_cols)
    button_ys = ys_per_row[label_idx // n_cols]
    label_xs = button_xs + button_text_offset
    label_ys = button_ys
```

Code after:
    def disconnect(self, cid):
        """Remove the observer with connection id *cid*."""
        self._observers.disconnect(cid)


class RadioButtons(_Buttons):
    """
    A GUI neutral radio button.

    For the buttons to remain responsive you must keep a reference to this
    object.

    Connect to the RadioButtons with the `~._Buttons.on_clicked` method.

    Attributes
    ----------
    ax : `~matplotlib.axes.Axes`
        The parent Axes for the widget.
    activecolor : :mpltype:`color`
        The color of the selected button.
    labels : list of `.Text`
        The button labels.
    value_selected : str
        The label text of the currently selected button.
    index_selected : int
        The index of the selected button.
    """

    def __init__(self, ax, labels, active=0, activecolor=None, *, layout=None,
                 useblit=True, label_props=None, radio_props=None):
        """
        Add radio buttons to an `~.axes.Axes`.

        Parameters
        ----------
        ax : `~matplotlib.axes.Axes`
            The Axes to add the buttons to.
        labels : list of str
            The button labels.
        active : int
            The index of the initially selected button.
        activecolor : :mpltype:`color`
            The color of the selected button. The default is ``'blue'`` if not
            specified here or in *radio_props*.
        layout : None or "vertical" or "horizontal" or (int, int), default: None
            The layout of the radio buttons. Options are:

            - ``None``: Use legacy vertical layout (default).
            - ``"vertical"``: Arrange buttons in a single column with
              dynamic positioning based on text widths.
            - ``"horizontal"``: Arrange buttons in a single row with