Skip to content

Commit

Permalink
Merge pull request #424 from astrofrog/random-sampling-histogram
Browse files Browse the repository at this point in the history
Expose ability to use a random subset of data for computing histograms
  • Loading branch information
astrofrog authored Apr 16, 2024
2 parents ad6ade4 + f112f3d commit 2dd85c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions glue_jupyter/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion glue_jupyter/bqplot/histogram/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')):
'hist_x_max', 'hist_n_bin', 'x_log',
'random_subset')):
self._calculate_histogram()
force = True # make sure scaling and visual attributes are updated

Expand Down

0 comments on commit 2dd85c2

Please sign in to comment.