def plot(self, metric="woe", n_samples=10000, savefig=None,
             save_kwargs=None):
        """Plot the binning table.

        Visualize the non-event and event count, and the predicted Weight of
        Evidence or event rate for each bin.

        Parameters
        ----------
        metric : str, optional (default="woe")
            Supported metrics are "woe" to show the Weight of Evidence (WoE)
            measure and "event_rate" to show the event rate.

        n_samples : int (default=10000)
            Number of samples to be represented.

        savefig : str or None (default=None)
            Path to save the plot figure.

        save_kwargs : dict or None (default=None)
            Additional keyword arguments to be passed to `plt.savefig`.
        """
        _check_is_built(self)

        if metric not in ("event_rate", "woe"):
            raise ValueError('Invalid value for metric. Allowed string '
                             'values are "event_rate" and "woe".')

        n_bins_extra = self._n_specials + 1
        _n_nonevent = self.n_nonevent[:-n_bins_extra]
        _n_event = self.n_event[:-n_bins_extra]

        n_splits = len(self.splits)

        y_pos = np.empty(n_splits + 2)
        y_pos[0] = self.min_x
        y_pos[1:-1] = self.splits
        y_pos[-1] = self.max_x

        width = y_pos[1:] - y_pos[:-1]
        y_pos = y_pos[:-1]

        fig, ax1 = plt.subplots()

        p2 = ax1.bar(y_pos, _n_event, width, color="tab:red", align="edge")
        p1 = ax1.bar(y_pos, _n_nonevent, width, color="tab:blue",
                     bottom=_n_event, align="edge")

        handles = [p1[0], p2[0]]
        labels = ['Non-event', 'Event']

        ax1.set_xlabel("x", fontsize=12)
        ax1.set_ylabel("Bin count", fontsize=13)
        ax1.tick_params(axis='x', labelrotation=45)

        ax2 = ax1.twinx()

        x_samples = np.linspace(self.min_x, self.max_x, n_samples)

        metric_values = transform_binary_target(
            self.splits, x_samples, self.coef, 0, 1, self._t_n_nonevent,
            self._t_n_event, 0, 0, 0, 0, [], metric, 0, 0)

        if metric == "woe":
            metric_label = "WoE"
        elif metric == "event_rate":
            metric_label = "Event rate"

        for split in self.splits:
            ax2.axvline(x=split, color="darkgrey", linestyle="--")

        ax2.plot(x_samples, metric_values, linestyle="solid", color="black")

        ax2.set_ylabel(metric_label, fontsize=13)

        plt.title(self.name, fontsize=14)
        plt.legend(handles, labels, loc="upper center",
                   bbox_to_anchor=(0.5, -0.2), ncol=2, fontsize=12)

        if savefig is None:
            plt.show()
        else:
            if not isinstance(savefig, str):
                raise TypeError("savefig must be a string path; got {}."
                                .format(savefig))
            if save_kwargs is None:
                save_kwargs = {}
            else:
                if not isinstance(save_kwargs, dict):
                    raise TypeError("save_kwargs must be a dictionary; got {}."
                                    .format(save_kwargs))
            plt.savefig(savefig, **save_kwargs)
            plt.close()
Plot the binning table.

        Visualize the non-event and event count, and the predicted Weight of
        Evidence or event rate for each bin.

        Parameters
        ----------
        metric : str, optional (default="woe")
            Supported metrics are "woe" to show the Weight of Evidence (WoE)
            measure and "event_rate" to show the event rate.

        n_samples : int (default=10000)
            Number of samples to be represented.

        savefig : str or None (default=None)
            Path to save the plot figure.

        save_kwargs : dict or None (default=None)
            Additional keyword arguments to be passed to `plt.savefig`.
        
optbinning/binning/piecewise/binning_statistics.py