def plot(self, add_special=True, add_missing=True, show_bin_labels=False,
             savefig=None, figsize=None):
        """Plot the binning table.

        Visualize event count and event rate values for each class.

        Parameters
        ----------
        add_special : bool (default=True)
            Whether to add the special codes bin.

        add_missing : bool (default=True)
            Whether to add the special values bin.

        show_bin_labels : bool (default=False)
            Whether to show the bin label instead of the bin id on the x-axis.
            For long labels (length > 27), labels are truncated.

            .. versionadded:: 0.15.1

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

        figsize : tuple or None (default=None)
            Size of the plot.
        """
        _check_is_built(self)

        if not isinstance(add_special, bool):
            raise TypeError("add_special must be a boolean; got {}."
                            .format(add_special))

        if not isinstance(add_missing, bool):
            raise TypeError("add_missing must be a boolean; got {}."
                            .format(add_missing))

        if not isinstance(show_bin_labels, bool):
            raise TypeError("show_bin_labels must be a boolean; got {}."
                            .format(show_bin_labels))

        if figsize is not None:
            if not isinstance(figsize, tuple):
                raise TypeError('figsize argument must be a tuple.')

        n_bins = len(self._n_records)
        n_metric = n_bins - 1 - self._n_specials
        n_classes = len(self.classes)

        fig, ax1 = plt.subplots(figsize=figsize)

        colors = COLORS_RGB[:n_classes]
        colors = [tuple(c / 255. for c in color) for color in colors]

        if not add_special:
            n_bins -= self._n_specials

        if not add_missing:
            n_bins -= 1

        _n_event = []
        for i in range(n_classes):
            _n_event_c = list(self.n_event[:, i])
            if not add_special:
                for _ in range(self._n_specials):
                    _n_event_c.pop(-2)
            if not add_missing:
                _n_event_c.pop(-1)
            _n_event.append(np.array(_n_event_c))

        _n_event = np.array(_n_event)

        p = []
        cum_size = np.zeros(n_bins)
        for i, cl in enumerate(self.classes):
            p.append(ax1.bar(range(n_bins), _n_event[i],
                             color=colors[i], bottom=cum_size))
            cum_size += _n_event[i]

        handles = [_p[0] for _p in p]
        labels = list(self.classes)

        ax1.set_xlabel("Bin ID", fontsize=12)
        ax1.set_ylabel("Bin count", fontsize=13)

        ax2 = ax1.twinx()

        metric_values = self._event_rate
        metric_label = "Event rate"

        for i, cl in enumerate(self.classes):
            ax2.plot(range(n_metric), metric_values[:n_metric, i],
                     linestyle="solid", marker="o", color="black",
                     markerfacecolor=colors[i], markeredgewidth=0.5)

        # Add points for special and missing bin
        if add_special:
            pos_special = n_metric
            if add_missing:
                pos_missing = n_metric + self._n_specials
        elif add_missing:
            pos_missing = n_metric

        if add_special:
            for _p in p:
                for i in range(self._n_specials):
                    _p[pos_special + i].set_hatch("/")

            handle_special = mpatches.Patch(hatch="/", alpha=0.1)
            label_special = "Bin special"

            for i, cl in enumerate(self.classes):
                for s in range(self._n_specials):
                    ax2.plot(pos_special+s, metric_values[pos_special+s, i],
                             marker="o", color=colors[i])

        if add_missing:
            for _p in p:
                _p[pos_missing].set_hatch("\\")

            handle_missing = mpatches.Patch(hatch="\\", alpha=0.1)
            label_missing = "Bin missing"

            for i, cl in enumerate(self.classes):
                ax2.plot(pos_missing, metric_values[pos_missing, i],
                         marker="o", color=colors[i])

        if add_special and add_missing:
            handles.extend([handle_special, handle_missing])
            labels.extend([label_special, label_missing])
        elif add_special:
            handles.extend([handle_special])
            labels.extend([label_special])
        elif add_missing:
            handles.extend([handle_missing])
            labels.extend([label_missing])

        ax2.set_ylabel(metric_label, fontsize=13)
        ax2.xaxis.set_major_locator(mtick.MultipleLocator(1))

        if show_bin_labels:
            bin_str = self._bin_str
            if not add_special:
                bin_str = bin_str[:-2] + [bin_str[-1]]

            if not add_missing:
                bin_str = bin_str[:-1]

            ax1.set_xlabel("Bin", fontsize=12)
            ax1.set_xticks(np.arange(len(bin_str)))
            ax1.set_xticklabels(bin_str, rotation=45, ha="right")

        plt.title(self.name, fontsize=14)

        if show_bin_labels:
            legend_high = max(map(len, self._bin_str)) / 70 + 0.2
            plt.legend(handles, labels, loc="upper center",
                       bbox_to_anchor=(0.5, -legend_high), ncol=2, fontsize=12)
        else:
            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))
            plt.savefig(savefig)
            plt.close()
Plot the binning table.

        Visualize event count and event rate values for each class.

        Parameters
        ----------
        add_special : bool (default=True)
            Whether to add the special codes bin.

        add_missing : bool (default=True)
            Whether to add the special values bin.

        show_bin_labels : bool (default=False)
            Whether to show the bin label instead of the bin id on the x-axis.
            For long labels (length > 27), labels are truncated.

            .. versionadded:: 0.15.1

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

        figsize : tuple or None (default=None)
            Size of the plot.
        
optbinning/binning/binning_statistics.py