From e298684b8e00158964e1c191cb9418299af1bffe Mon Sep 17 00:00:00 2001 From: Jerome Dockes Date: Wed, 10 Jan 2024 16:39:04 +0100 Subject: [PATCH] remove top and right spines --- src/skrubview/_plotting.py | 9 ++++++++- src/skrubview/_summarize.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/skrubview/_plotting.py b/src/skrubview/_plotting.py index 5e1866d..033428d 100644 --- a/src/skrubview/_plotting.py +++ b/src/skrubview/_plotting.py @@ -24,6 +24,10 @@ COLOR_0 = COLORS[0] +def _despine(ax): + ax.spines[["top", "right"]].set_visible(False) + + def _serialize(fig, close=True): buffer = io.BytesIO() fig.savefig(buffer, format="svg", bbox_inches="tight") @@ -43,6 +47,7 @@ def _rotate_ticklabels(ax): def histogram(col, title=None, color=COLOR_0): values = np.asarray(col.to_array()) fig, ax = plt.subplots(figsize=(3, 1.5), layout="compressed") + _despine(ax) ax.hist(values, color=color) if title is not None: ax.set_title(title) @@ -54,6 +59,7 @@ def line(x_col, y_col): x = np.asarray(x_col.to_array()) y = np.asarray(y_col.to_array()) fig, ax = plt.subplots(figsize=(3, 2), layout="compressed") + _despine(ax) ax.plot(x, y) ax.set_xlabel(x_col.name) ax.set_ylabel(y_col.name) @@ -67,11 +73,12 @@ def value_counts(value_counts, n_unique, color=COLOR_0): height = 0.2 * (len(value_counts) + 1.1) if n_unique > len(value_counts): title = f"{len(value_counts)} most frequent out of {n_unique}" - height += .5 + height += 0.5 else: title = None width = 0.1 * max(len(str(v)) for v in values) + 2 fig, ax = plt.subplots(figsize=(width, height), layout="compressed") + _despine(ax) ax.barh(list(map(str, values)), counts, color=color) if title is not None: ax.set_title(title) diff --git a/src/skrubview/_summarize.py b/src/skrubview/_summarize.py index e845df5..26470ff 100644 --- a/src/skrubview/_summarize.py +++ b/src/skrubview/_summarize.py @@ -167,7 +167,7 @@ def _add_numeric_summary(summary, column, with_plots, order_by_column): return if order_by_column is None: summary["histogram_plot"] = _plotting.histogram( - column, "Value distribution", color=_plotting.COLORS[0] + column, title=None, color=_plotting.COLORS[0] ) else: summary["line_plot"] = _plotting.line(order_by_column, column)