Repository: scikit-learn/scikit-learn
File: sklearn/inspection/_plot/decision_boundary.py (Python)

Code before:
                if kwarg in kwargs:
                    warnings.warn(
                        f"'{kwarg}' is ignored in favor of 'multiclass_colors' "
                        "in the multiclass case."
                    )
                    del kwargs[kwarg]

            if self.multiclass_colors is None or isinstance(
                self.multiclass_colors, str
            ):
                if self.multiclass_colors is None:
                    cmap = "tab10" if self.n_classes <= 10 else "gist_rainbow"
                else:
                    cmap = self.multiclass_colors

                # Special case for the tab10 and tab20 colormaps that encode a
                # discrete set of colors that are easily distinguishable
                # contrary to other colormaps that are continuous.
                if cmap == "tab10" and self.n_classes <= 10:
                    colors = plt.get_cmap("tab10", 10).colors[: self.n_classes]
                elif cmap == "tab20" and self.n_classes <= 20:
                    colors = plt.get_cmap("tab20", 20).colors[: self.n_classes]
                else:
                    cmap = plt.get_cmap(cmap, self.n_classes)
                    if not hasattr(cmap, "colors"):
                        # For LinearSegmentedColormap
                        colors = cmap(np.linspace(0, 1, self.n_classes))
                    else:
                        colors = cmap.colors
            elif isinstance(self.multiclass_colors, list):
                colors = [mpl.colors.to_rgba(color) for color in self.multiclass_colors]
            else:
                raise ValueError("'multiclass_colors' must be a list or a str.")

            self.multiclass_colors_ = colors

            if plot_method == "contour":
                # Plot only argmax
                response = (
                    self.response.argmax(axis=2)
                    if self.response.ndim == 3
                    else self.response
                )
                self.surface_ = plot_func(
                    self.xx0, self.xx1, response, colors=colors, **kwargs
                )
            elif plot_method == "pcolormesh" and self.response.ndim == 2:  # predict
                cmap = mpl.colors.ListedColormap(colors)
                self.surface_ = plot_func(
                    self.xx0, self.xx1, self.response, cmap=cmap, **kwargs
                )

Review comment (suggestion):
```suggestion
                        # Get `LinearSegmentedColormap` for non-qualitative cmaps
```

unrelated but lets add for clarity

Code after:
        """
        check_matplotlib_support("DecisionBoundaryDisplay.plot")
        import matplotlib as mpl
        import matplotlib.pyplot as plt

        if plot_method not in ("contourf", "contour", "pcolormesh"):
            raise ValueError(
                "plot_method must be 'contourf', 'contour', or 'pcolormesh'. "
                f"Got {plot_method} instead."
            )

        if ax is None:
            _, ax = plt.subplots()

        plot_func = getattr(ax, plot_method)
        if self.n_classes == 2:
            self.surface_ = plot_func(self.xx0, self.xx1, self.response, **kwargs)
        else:  # multiclass
            for kwarg in ("cmap", "colors"):
                if kwarg in kwargs:
                    warnings.warn(
                        f"'{kwarg}' is ignored in favor of 'multiclass_colors' "
                        "in the multiclass case."
                    )
                    del kwargs[kwarg]

            if self.multiclass_colors is None or isinstance(
                self.multiclass_colors, str
            ):
                if self.multiclass_colors is None:
                    cmap = "tab10" if self.n_classes <= 10 else "gist_rainbow"
                else:
                    cmap = self.multiclass_colors

                # Special case for the tab10 and tab20 colormaps that encode a
                # discrete set of colors that are easily distinguishable
                # contrary to other colormaps that are continuous.
                if cmap == "tab10" and self.n_classes <= 10:
                    colors = plt.get_cmap("tab10", 10).colors[: self.n_classes]
                elif cmap == "tab20" and self.n_classes <= 20:
                    colors = plt.get_cmap("tab20", 20).colors[: self.n_classes]
                else:
                    cmap = plt.get_cmap(cmap, self.n_classes)
                    if not hasattr(cmap, "colors"):
                        # Get `LinearSegmentedColormap` for non-qualitative cmaps
                        colors = cmap(np.linspace(0, 1, self.n_classes))
                    else:
                        colors = cmap.colors
            elif isinstance(self.multiclass_colors, list):
                colors = [mpl.colors.to_rgba(color) for color in self.multiclass_colors]
            else: