Skip to content

Commit

Permalink
Fix log axis lower bound when data minimum is <= 0 (#5246)
Browse files Browse the repository at this point in the history
* Fix log axis lower bound when data minimum is <= 0

Set the lower bound as originally intended in #1691

* Update tests

* Fix barplot

Co-authored-by: Philipp Rudiger <[email protected]>
  • Loading branch information
TheoMathurin and philippjfr authored Apr 8, 2022
1 parent 1365174 commit 7930d08
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ def get_data(self, element, ranges, style):

y0, y1 = ranges.get(ydim.name, {'combined': (None, None)})['combined']
if self.logy:
bottom = (ydim.range[0] or (10**(np.log10(y1)-2)) if y1 else 0.01)
bottom = (ydim.range[0] or (0.01 if y1 > 0.01 else 10**(np.log10(y1)-2)))
else:
bottom = 0
# Map attributes to data
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def _update_range(self, axis_range, low, high, factors, invert, shared, log, str
low, high = util.max_range([(low, high), shared])
if invert: low, high = high, low
if not isinstance(low, util.datetime_types) and log and (low is None or low <= 0):
low = 0.01 if high < 0.01 else 10**(np.log10(high)-2)
low = 0.01 if high > 0.01 else 10**(np.log10(high)-2)
self.param.warning(
"Logarithmic axis range encountered value less "
"than or equal to zero, please supply explicit "
Expand Down
2 changes: 1 addition & 1 deletion holoviews/tests/plotting/bokeh/test_areaplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_area_padding_logy(self):
x_range, y_range = plot.handles['x_range'], plot.handles['y_range']
self.assertEqual(x_range.start, 0.8)
self.assertEqual(x_range.end, 3.2)
self.assertEqual(y_range.start, 0.033483695221017122)
self.assertEqual(y_range.start, 0.01)
self.assertEqual(y_range.end, 3.3483695221017129)
self.log_handler.assertContains('WARNING', 'Logarithmic axis range encountered value less than')

Expand Down
6 changes: 3 additions & 3 deletions holoviews/tests/plotting/bokeh/test_barplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def test_bars_logy(self):
y_range = plot.handles['y_range']
self.assertEqual(list(source.data['Index']), ['A', 'B', 'C'])
self.assertEqual(source.data['Value'], np.array([1, 2, 3]))
self.assertEqual(glyph.bottom, 10**(np.log10(3)-2))
self.assertEqual(y_range.start, 0.03348369522101712)
self.assertEqual(glyph.bottom, 0.01)
self.assertEqual(y_range.start, 0.01)
self.assertEqual(y_range.end, 3.348369522101713)

def test_bars_logy_explicit_range(self):
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_bars_padding_logy(self):
bars = Bars([(1, 2), (2, 1), (3, 3)]).options(padding=0.1, logy=True)
plot = bokeh_renderer.get_plot(bars)
y_range = plot.handles['y_range']
self.assertEqual(y_range.start, 0.033483695221017122)
self.assertEqual(y_range.start, 0.01)
self.assertEqual(y_range.end, 3.3483695221017129)

###########################
Expand Down
2 changes: 1 addition & 1 deletion holoviews/tests/plotting/bokeh/test_histogramplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_histogram_padding_logy(self):
x_range, y_range = plot.handles['x_range'], plot.handles['y_range']
self.assertEqual(x_range.start, 0.19999999999999996)
self.assertEqual(x_range.end, 3.8)
self.assertEqual(y_range.start, 0.033483695221017122)
self.assertEqual(y_range.start, 0.01)
self.assertEqual(y_range.end, 3.3483695221017129)
self.log_handler.assertContains('WARNING', 'Logarithmic axis range encountered value less than')

Expand Down

0 comments on commit 7930d08

Please sign in to comment.