Skip to content

Commit

Permalink
add min, max and autoscaling range options to histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
Iara Ota committed Nov 14, 2023
1 parent 23c97f8 commit 8489674
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions gwsumm/plot/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Check warning on line 725 in gwsumm/plot/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/plot/builtin.py#L724-L725

Added lines #L724 - L725 were not covered by tests
# 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])

Check warning on line 728 in gwsumm/plot/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/plot/builtin.py#L727-L728

Added lines #L727 - L728 were not covered by tests
# 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)

Check warning on line 731 in gwsumm/plot/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/plot/builtin.py#L730-L731

Added lines #L730 - L731 were not covered by tests

# Remove data with range smaller than 1 Mpc for cumulative plot
if self.type == 'range-cumulative-histogram':
arr = numpy.array(arr)
Expand Down
2 changes: 1 addition & 1 deletion gwsumm/plot/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8489674

Please sign in to comment.