Skip to content

Commit

Permalink
Merge pull request guillermo-navas-palencia#279 from alexliap/adjust_…
Browse files Browse the repository at this point in the history
…plot_size

Adjust plot size
  • Loading branch information
guillermo-navas-palencia authored Dec 6, 2023
2 parents 3754085 + 53b9033 commit 3941883
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions optbinning/binning/binning_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def build(self, show_digits=2, add_totals=True):
return df

def plot(self, metric="woe", add_special=True, add_missing=True,
style="bin", show_bin_labels=False, savefig=None):
style="bin", show_bin_labels=False, savefig=None, figsize=None):
"""Plot the binning table.
Visualize the non-event and event count, and the Weight of Evidence or
Expand Down Expand Up @@ -637,6 +637,9 @@ def plot(self, metric="woe", add_special=True, add_missing=True,
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)

Expand Down Expand Up @@ -664,6 +667,10 @@ def plot(self, metric="woe", add_special=True, add_missing=True,
raise ValueError('show_bin_labels only supported when '
'style="actual".')

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

if style == "actual":
# Hide special and missing bin
add_special = False
Expand All @@ -683,7 +690,7 @@ def plot(self, metric="woe", add_special=True, add_missing=True,
metric_values = self._event_rate
metric_label = "Event rate"

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

if style == "bin":
n_bins = len(self._n_records)
Expand Down Expand Up @@ -1204,7 +1211,7 @@ def build(self, show_digits=2, add_totals=True):
return df

def plot(self, add_special=True, add_missing=True, show_bin_labels=False,
savefig=None):
savefig=None, figsize=None):
"""Plot the binning table.
Visualize event count and event rate values for each class.
Expand All @@ -1225,6 +1232,9 @@ def plot(self, add_special=True, add_missing=True, show_bin_labels=False,
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)

Expand All @@ -1240,11 +1250,15 @@ def plot(self, add_special=True, add_missing=True, show_bin_labels=False,
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()
fig, ax1 = plt.subplots(figsize=figsize)

colors = COLORS_RGB[:n_classes]
colors = [tuple(c / 255. for c in color) for color in colors]
Expand Down Expand Up @@ -1548,7 +1562,7 @@ class ContinuousBinningTable:
def __init__(self, name, dtype, special_codes, splits, n_records, sums,
stds, min_target, max_target, n_zeros, min_x=None, max_x=None,
categories=None, cat_others=None, user_splits=None):

self.name = name
self.dtype = dtype
self.special_codes = special_codes
Expand Down Expand Up @@ -1665,7 +1679,7 @@ def build(self, show_digits=2, add_totals=True):
return df

def plot(self, add_special=True, add_missing=True, style="bin",
show_bin_labels=False, savefig=None):
show_bin_labels=False, savefig=None, figsize=None):
"""Plot the binning table.
Visualize records count and mean values.
Expand All @@ -1691,6 +1705,9 @@ def plot(self, add_special=True, add_missing=True, style="bin",
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)

Expand All @@ -1714,6 +1731,10 @@ def plot(self, add_special=True, add_missing=True, style="bin",
raise ValueError('show_bin_labels only supported when '
'style="actual".')

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

if style == "actual":
# Hide special and missing bin
add_special = False
Expand All @@ -1729,7 +1750,7 @@ def plot(self, add_special=True, add_missing=True, style="bin",
metric_values = self._mean
metric_label = "Mean"

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

if style == "bin":
n_bins = len(self.n_records)
Expand Down Expand Up @@ -2039,3 +2060,4 @@ def quality_score(self):
_check_is_analyzed(self)

return self._quality_score

0 comments on commit 3941883

Please sign in to comment.