From 8489674573910261dff6b1768733c441018c15ae Mon Sep 17 00:00:00 2001 From: Iara Ota Date: Mon, 13 Nov 2023 19:17:07 -0600 Subject: [PATCH] add min, max and autoscaling range options to histograms --- gwsumm/plot/builtin.py | 14 +++++++++++--- gwsumm/plot/range.py | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gwsumm/plot/builtin.py b/gwsumm/plot/builtin.py index 154fca7c..77abb347 100644 --- a/gwsumm/plot/builtin.py +++ b/gwsumm/plot/builtin.py @@ -711,9 +711,7 @@ def draw(self, outputfile=None): # plot for ax, arr, pargs in zip(cycle(axes), data, histargs): # set range if not given - # but leave is as None in the cumulative histogram, this avoids - # the histogram to extend to x > y(x) = 1 - if pargs.get('range') is None and self.type != 'range-cumulative-histogram': + if pargs.get('range') is None: pargs['range'] = self._get_range( data, # use range from first dataset if already calculated @@ -722,6 +720,16 @@ def draw(self, outputfile=None): xlim=None if ax.get_autoscalex_on() else ax.get_xlim(), ) + # Add the option to enable autoscaling + if pargs.get('range') == 'autoscaling': + pargs['range'] = None + # Add option to set the minimum range based on the data + if pargs.get('range')[0] == 'min': + pargs['range'] = (arr.min().value, pargs['range'][1]) + # Add option to set the maximum range based on the data + if pargs.get('range')[1] == 'max': + pargs['range'] = (pargs['range'][0], arr.max().value) + # Remove data with range smaller than 1 Mpc for cumulative plot if self.type == 'range-cumulative-histogram': arr = numpy.array(arr) diff --git a/gwsumm/plot/range.py b/gwsumm/plot/range.py index 05524c2b..aaacc986 100644 --- a/gwsumm/plot/range.py +++ b/gwsumm/plot/range.py @@ -162,12 +162,12 @@ class RangeCumulativeHistogramPlot(RangePlotMixin, get_plot('histogram')): 'log': False, 'cumulative': True, 'density': True, + 'range': (1, 'max'), }) register_plot(RangeCumulativeHistogramPlot) - class RangeSpectrogramDataPlot(RangePlotMixin, get_plot('spectrogram')): type = 'range-spectrogram' defaults = get_plot('spectrogram').defaults.copy()