From 7aeec4b3469aae55e7bbb051857d823530ba6b6a Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 19 Mar 2024 10:36:36 +0000 Subject: [PATCH 1/2] Expose ability to use a random subset of data for computing histograms --- glue_jupyter/app.py | 8 ++++++-- glue_jupyter/bqplot/histogram/layer_artist.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/glue_jupyter/app.py b/glue_jupyter/app.py index 1f3721e4..ea2a46bc 100644 --- a/glue_jupyter/app.py +++ b/glue_jupyter/app.py @@ -234,7 +234,7 @@ def table(self, *, data=None, x=None, widget='ipyvuetify', viewer_state=None, def histogram1d(self, *, data=None, x=None, widget='bqplot', color=None, x_min=None, x_max=None, n_bin=None, normalize=False, - cumulative=False, viewer_state=None, layer_state=None, + cumulative=False, random_subset=None, viewer_state=None, layer_state=None, show=True): """ Open an interactive histogram viewer. @@ -262,6 +262,10 @@ def histogram1d(self, *, data=None, x=None, widget='bqplot', color=None, Whether to normalize the histogram. cumulative : bool, optional Whether to show a cumulative histogram. + random_subset : int, optional + The maximum number of elements to use when computing a histogram. + If there are more than this number of data points, a random subset + is used. viewer_state : `~glue.viewers.common.state.ViewerState` The initial state for the viewer (advanced). layer_state : `~glue.viewers.common.state.LayerState` @@ -294,7 +298,7 @@ def histogram1d(self, *, data=None, x=None, widget='bqplot', color=None, # glue.viewers.histogram.state for this API it make more sense to call # it x_min and x_max, and for consistency with the rest _update_not_none(viewer_state, hist_x_min=x_min, hist_x_max=x_max, hist_n_bin=n_bin, - normalize=normalize, cumulative=cumulative) + normalize=normalize, cumulative=cumulative, random_subset=random_subset) viewer_state_obj.update_from_dict(viewer_state) view = self.new_data_viewer(viewer_cls, data=data, diff --git a/glue_jupyter/bqplot/histogram/layer_artist.py b/glue_jupyter/bqplot/histogram/layer_artist.py index ddd578db..76072960 100644 --- a/glue_jupyter/bqplot/histogram/layer_artist.py +++ b/glue_jupyter/bqplot/histogram/layer_artist.py @@ -138,7 +138,7 @@ def _update_histogram(self, force=False, **kwargs): changed = self.pop_changed_properties() if force or any(prop in changed for prop in ('layer', 'x_att', 'hist_x_min', - 'hist_x_max', 'hist_n_bin', 'x_log')): + 'hist_x_max', 'hist_n_bin', 'x_log', 'random_subset')): self._calculate_histogram() force = True # make sure scaling and visual attributes are updated From f112f3dec52280f3a16bd07bd4e09c8424837fba Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 16 Apr 2024 13:02:22 +0100 Subject: [PATCH 2/2] Fix code style --- glue_jupyter/bqplot/histogram/layer_artist.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glue_jupyter/bqplot/histogram/layer_artist.py b/glue_jupyter/bqplot/histogram/layer_artist.py index 76072960..5f71814f 100644 --- a/glue_jupyter/bqplot/histogram/layer_artist.py +++ b/glue_jupyter/bqplot/histogram/layer_artist.py @@ -138,7 +138,8 @@ def _update_histogram(self, force=False, **kwargs): changed = self.pop_changed_properties() if force or any(prop in changed for prop in ('layer', 'x_att', 'hist_x_min', - 'hist_x_max', 'hist_n_bin', 'x_log', 'random_subset')): + 'hist_x_max', 'hist_n_bin', 'x_log', + 'random_subset')): self._calculate_histogram() force = True # make sure scaling and visual attributes are updated