From 90f5cff4b5706df7ac0854202e4a83b1dc0ff175 Mon Sep 17 00:00:00 2001 From: samadpls Date: Wed, 20 Mar 2024 00:19:26 +0500 Subject: [PATCH] Updated kwargs options for plot_spikes_hist parent 54bd27805198f8c345efe307b2860ad271f1dc3f author samadpls 1710875966 +0500 committer samadpls 1712241138 +0500 Added `kwargs` options to `plot_spikes_hist` Signed-off-by: samadpls refactored removed extra line --- doc/whats_new.rst | 3 +++ hnn_core/cell_response.py | 6 ++++-- hnn_core/tests/test_cell_response.py | 6 +++++- hnn_core/viz.py | 6 ++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 72a0dac41a..669ed27cbd 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -43,6 +43,9 @@ Changelog returned for cases when there should be no valid matches, by `George Dang`_ in :gh:`739` +- Added kwargs options to `plot_spikes_hist` for adjusting the histogram plots of spiking activity, + by `Abdul Samad`_ in :gh:`732`. + Bug ~~~ - Fix inconsistent connection mapping from drive gids to cell gids, by diff --git a/hnn_core/cell_response.py b/hnn_core/cell_response.py index 712d0fc565..13386d9da8 100644 --- a/hnn_core/cell_response.py +++ b/hnn_core/cell_response.py @@ -349,7 +349,7 @@ def plot_spikes_raster(self, trial_idx=None, ax=None, show=True): cell_response=self, trial_idx=trial_idx, ax=ax, show=show) def plot_spikes_hist(self, trial_idx=None, ax=None, spike_types=None, - color=None, show=True): + color=None, show=True, **kwargs_hist): """Plot the histogram of spiking activity across trials. Parameters @@ -392,6 +392,8 @@ def plot_spikes_hist(self, trial_idx=None, ax=None, spike_types=None, If None, default color cycle used. show : bool If True, show the figure. + **kwargs_hist : dict + Additional keyword arguments to pass to ax.hist. Returns ------- @@ -400,7 +402,7 @@ def plot_spikes_hist(self, trial_idx=None, ax=None, spike_types=None, """ return plot_spikes_hist(self, trial_idx=trial_idx, ax=ax, spike_types=spike_types, color=color, - show=show) + show=show, **kwargs_hist) def to_dict(self): """Return cell response as a dict object. diff --git a/hnn_core/tests/test_cell_response.py b/hnn_core/tests/test_cell_response.py index ce0373db1d..06730dccdd 100644 --- a/hnn_core/tests/test_cell_response.py +++ b/hnn_core/tests/test_cell_response.py @@ -24,7 +24,11 @@ def test_cell_response(tmp_path): spike_gids=spike_gids, spike_types=spike_types, times=sim_times) - cell_response.plot_spikes_hist(show=False) + kwargs_hist = dict(alpha=0.25) + fig = cell_response.plot_spikes_hist(show=False, **kwargs_hist) + assert all(patch.get_alpha() == kwargs_hist['alpha'] + for patch in fig.axes[0].patches + ), "Alpha value not applied to all patches" # Testing writing using txt files with pytest.warns(DeprecationWarning, diff --git a/hnn_core/viz.py b/hnn_core/viz.py index f63a7514e4..d9abe7d76d 100644 --- a/hnn_core/viz.py +++ b/hnn_core/viz.py @@ -323,7 +323,7 @@ def plot_dipole(dpl, tmin=None, tmax=None, ax=None, layer='agg', decim=None, def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, - color=None, show=True): + color=None, show=True, **kwargs_hist): """Plot the histogram of spiking activity across trials. Parameters @@ -369,6 +369,8 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, If None, default color cycle used. show : bool If True, show the figure. + **kwargs : dict + Additional keyword arguments to pass to ax.hist. Returns ------- @@ -473,7 +475,7 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, for spike_label, plot_data in spike_type_times.items(): hist_color = spike_color[spike_label] ax.hist(plot_data, bins, - label=spike_label, color=hist_color) + label=spike_label, color=hist_color, **kwargs_hist) ax.set_ylabel("Counts") ax.legend()