|
34 | 34 | from functools import wraps |
35 | 35 |
|
36 | 36 | import numpy as np |
| 37 | +import math |
37 | 38 |
|
38 | 39 | import matplotlib as mpl |
39 | 40 | from matplotlib import _api, _docstring |
@@ -122,8 +123,11 @@ def val_in_range(self, val): |
122 | 123 | efficient solutions for their domain. |
123 | 124 | """ |
124 | 125 | try: |
125 | | - vmin, vmax = self.limit_range_for_scale(val, val, minpos=1e-300) |
126 | | - return vmin == val and vmax == val |
| 126 | + if not math.isfinite(val): |
| 127 | + return False |
| 128 | + else: |
| 129 | + vmin, vmax = self.limit_range_for_scale(val, val, minpos=1e-300) |
| 130 | + return vmin == val and vmax == val |
127 | 131 | except (TypeError, ValueError): |
128 | 132 | return False |
129 | 133 |
|
@@ -213,9 +217,9 @@ def val_in_range(self, val): |
213 | 217 | """ |
214 | 218 | Return whether the value is within the valid range for this scale. |
215 | 219 |
|
216 | | - This is True for all values. |
| 220 | + This is True for all values, except +-inf and NaN. |
217 | 221 | """ |
218 | | - return True |
| 222 | + return math.isfinite(val) |
219 | 223 |
|
220 | 224 |
|
221 | 225 | class FuncTransform(Transform): |
@@ -425,9 +429,9 @@ def val_in_range(self, val): |
425 | 429 | """ |
426 | 430 | Return whether the value is within the valid range for this scale. |
427 | 431 |
|
428 | | - This is True for value(s) > 0 |
| 432 | + This is True for value(s) > 0 except +inf. |
429 | 433 | """ |
430 | | - if np.isnan(val): |
| 434 | + if not math.isfinite(val): |
431 | 435 | return False |
432 | 436 | else: |
433 | 437 | return val > 0 |
@@ -613,6 +617,14 @@ def get_transform(self): |
613 | 617 | """Return the `.SymmetricalLogTransform` associated with this scale.""" |
614 | 618 | return self._transform |
615 | 619 |
|
| 620 | + def val_in_range(self, val): |
| 621 | + """ |
| 622 | + Return whether the value is within the valid range for this scale. |
| 623 | +
|
| 624 | + This is True for all values, except +-inf and NaN. |
| 625 | + """ |
| 626 | + return math.isfinite(val) |
| 627 | + |
616 | 628 |
|
617 | 629 | class AsinhTransform(Transform): |
618 | 630 | """Inverse hyperbolic-sine transformation used by `.AsinhScale`""" |
@@ -739,6 +751,14 @@ def set_default_locators_and_formatters(self, axis): |
739 | 751 | else: |
740 | 752 | axis.set_major_formatter('{x:.3g}') |
741 | 753 |
|
| 754 | + def val_in_range(self, val): |
| 755 | + """ |
| 756 | + Return whether the value is within the valid range for this scale. |
| 757 | +
|
| 758 | + This is True for all values, except +-inf and NaN. |
| 759 | + """ |
| 760 | + return math.isfinite(val) |
| 761 | + |
742 | 762 |
|
743 | 763 | class LogitTransform(Transform): |
744 | 764 | input_dims = output_dims = 1 |
|
0 commit comments