diff --git a/gwsumm/plot/__init__.py b/gwsumm/plot/__init__.py index 2f5ab46e..cdb50a87 100644 --- a/gwsumm/plot/__init__.py +++ b/gwsumm/plot/__init__.py @@ -99,6 +99,7 @@ RangeSpectrogramDataPlot, RangeSpectrumDataPlot, RangeCumulativeSpectrumDataPlot, + RangeCumulativeHistogramPlot, SimpleTimeVolumeDataPlot, GWpyTimeVolumeDataPlot, ) diff --git a/gwsumm/plot/builtin.py b/gwsumm/plot/builtin.py index ec84e8cc..7c56f365 100644 --- a/gwsumm/plot/builtin.py +++ b/gwsumm/plot/builtin.py @@ -710,15 +710,14 @@ def draw(self, outputfile=None): # plot for ax, arr, pargs in zip(cycle(axes), data, histargs): - # set range if not given - if pargs.get('range') is None: - pargs['range'] = self._get_range( - data, - # use range from first dataset if already calculated - range=histargs[0].get('range'), - # use xlim if manually set (user or INI) - xlim=None if ax.get_autoscalex_on() else ax.get_xlim(), - ) + # set range + pargs['range'] = self._get_range( + data, + # use range from first dataset if already calculated + range=histargs[0].get('range'), + # use xlim if manually set (user or INI) + xlim=None if ax.get_autoscalex_on() else ax.get_xlim(), + ) # plot histogram _, _, patches = ax.hist(arr, **pargs) @@ -759,8 +758,23 @@ def draw(self, outputfile=None): return self.finalize(outputfile=outputfile) def _get_range(self, data, range=None, xlim=None): - if range is not None or xlim is not None: - return range or xlim + if range is not None: + if range == 'autoscaling': + return None + else: + range = list(range) + try: + if range[0] == 'min': + range[0] = numpy.min(data) + if range[1] == 'max': + range[1] = numpy.max(data) + if range[0] < range[1]: + return range + except (ValueError, IndexError) as exc: + if not str(exc).startswith('zero-size array'): + raise + if xlim is not None: + return xlim try: return numpy.min(data), numpy.max(data) except ValueError as exc: diff --git a/gwsumm/plot/range.py b/gwsumm/plot/range.py index 2688e99e..56e6ccb6 100644 --- a/gwsumm/plot/range.py +++ b/gwsumm/plot/range.py @@ -153,6 +153,23 @@ class RangeDataHistogramPlot(RangePlotMixin, get_plot('histogram')): register_plot(RangeDataHistogramPlot) +class RangeCumulativeHistogramPlot(RangePlotMixin, get_plot('histogram')): + type = 'range-cumulative-histogram' + defaults = get_plot('histogram').defaults.copy() + defaults.update(RangePlotMixin.defaults.copy()) + defaults.update({ + 'xlabel': 'Angle-averaged range [Mpc]', + 'ylabel': 'Cumulative time duration', + '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() diff --git a/gwsumm/tabs/data.py b/gwsumm/tabs/data.py index aec3e7d8..7d7bb493 100644 --- a/gwsumm/tabs/data.py +++ b/gwsumm/tabs/data.py @@ -266,7 +266,8 @@ def from_ini(cls, cp, section, plotdir='plots', **kwargs): if cp.has_section(pdef): type_ = cp.get(pdef, 'type') PlotClass = get_plot(type_) - elif (pdef not in ['range-histogram', 'segment-histogram'] and + elif (pdef not in ['range-histogram', 'segment-histogram', + 'range-cumulative-histogram'] and pdef.endswith('-histogram')): type_ = None etg, column = pdef.rsplit('-', 2)[:2]