From 30f455c0dd92250e41fb6f7600ff8db18124e8a4 Mon Sep 17 00:00:00 2001 From: erdogant Date: Sun, 16 Apr 2023 20:57:29 +0200 Subject: [PATCH] add jitter and update docstring --- scatterd/__init__.py | 2 +- scatterd/scatterd.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scatterd/__init__.py b/scatterd/__init__.py index 44a2a08..f788be2 100644 --- a/scatterd/__init__.py +++ b/scatterd/__init__.py @@ -2,7 +2,7 @@ __author__ = 'Erdogan Tasksen' __email__ = 'erdogant@gmail.com' -__version__ = '1.2.5' +__version__ = '1.2.6' # module level doc-string __doc__ = """ diff --git a/scatterd/scatterd.py b/scatterd/scatterd.py index 7011147..7df8f92 100644 --- a/scatterd/scatterd.py +++ b/scatterd/scatterd.py @@ -33,6 +33,7 @@ def scatterd(x, figsize=(25, 15), legend=True, ax=None, + jitter=None, xlabel='x-axis', ylabel='y-axis', title='', fontsize=24, fontcolor=None, axiscolor='#dddddd', args_density = {'cmap': 'Reds', 'shade': True, 'thresh': 0.05, 'bw_adjust': .6, 'alpha': 0.66, 'legend': False, 'cbar': False, 'fill': True}): """Make scaterplot. @@ -69,6 +70,10 @@ def scatterd(x, [0,0,0] : If the input is a single color, all fonts will get this color. norm : Bool, optional Normalize datapoints. The default is False. + legend : bool, (default: False) + Plot the legend. + jitter : float, default: None + Add jitter to data points as random normal data. Values of 0.01 is usually good for one-hot data seperation. cmap : String, optional 'Set1' (default) 'Set2' @@ -136,6 +141,11 @@ def scatterd(x, defaults_kde = {'cmap': 'Reds', 'shade': True, 'thresh': 0.05, 'bw_adjust': .6, 'alpha': 0.66, 'legend': False, 'cbar': False, 'fill': True} args_density = {**defaults_kde, **args_density} + # Add jitter + if jitter is not None: + x = x + np.random.normal(0, jitter, size=1) + y = y + np.random.normal(0, jitter, size=1) + # Preprocessing X, labels = _preprocessing(x, y, z, labels, norm)