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

Code before:
                    for text in self.labels[col_idx::n_cols]
                ),
                default=0,
            )
            / axes_width_display
            for col_idx in range(n_cols)
        ]

        # 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
            )
        label_idx = np.arange(n_labels)
        self._buttons_xs = np.take(col_x_positions, label_idx % n_cols)
        self._buttons_ys = ys_per_row[label_idx // n_cols]
        for text,x,y in zip(self.labels, self._buttons_xs + button_text_offset,
                            self._buttons_ys):
            text.set_x(x)
            text.set_y(y)
            self.ax.add_artist(text)

    def _init_props(self, text_size, **kwargs):
        raise NotImplementedError("This method should be defined in subclasses")

    def _clear(self, event):
        """Internal event handler to clear the buttons."""
        if self.ignore(event) or self.canvas.is_saving():
            return
        if self._useblit and self.canvas.supports_blit:
            self._save_blit_background(self.canvas.copy_from_bbox(self.ax.bbox))
        self.ax.draw_artist(self._buttons)

    def set_label_props(self, props):
        """
        Set properties of the `.Text` labels.

        .. versionadded:: 3.7

        Parameters
        ----------
        props : dict
            Dictionary of `.Text` properties to be used for the labels. Same
            format as label_props argument of :class:`RadioButtons` or
            :class:`CheckButtons`.

Review comment (suggestion):
Logically equivalent, but slightly more readable:
```suggestion
        for text, x, y in zip(self.labels, self._buttons_xs, self._buttons_ys):
            text.set_position((x + button_text_offset, y))
```

Code after:
                ),
                default=0,
            )
            / axes_width_display
            for col_idx in range(n_cols)
        ]

        # 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
            )
        label_idx = np.arange(n_labels)
        self._buttons_xs = np.take(col_x_positions, label_idx % n_cols)
        self._buttons_ys = ys_per_row[label_idx // n_cols]
        for text, x, y in zip(self.labels, self._buttons_xs, self._buttons_ys):
            text.set_position((x + button_text_offset, y))
            self.ax.add_artist(text)

    def _init_props(self, text_size, **kwargs):
        raise NotImplementedError("This method should be defined in subclasses")

    def _clear(self, event):
        """Internal event handler to clear the buttons."""
        if self.ignore(event) or self.canvas.is_saving():
            return
        if self._useblit and self.canvas.supports_blit:
            self._save_blit_background(self.canvas.copy_from_bbox(self.ax.bbox))
        self.ax.draw_artist(self._buttons)

    def set_label_props(self, props):
        """
        Set properties of the `.Text` labels.

        .. versionadded:: 3.7

        Parameters
        ----------
        props : dict
            Dictionary of `.Text` properties to be used for the labels. Same
            format as label_props argument of :class:`RadioButtons` or
            :class:`CheckButtons`.
        """
        _api.check_isinstance(dict, props=props)
        props = _expand_text_props(props)