|
30 | 30 | """ # noqa: E501 |
31 | 31 |
|
32 | 32 | import inspect |
| 33 | +import math |
33 | 34 | import textwrap |
34 | 35 | from functools import wraps |
35 | 36 |
|
@@ -114,6 +115,22 @@ def limit_range_for_scale(self, vmin, vmax, minpos): |
114 | 115 | """ |
115 | 116 | return vmin, vmax |
116 | 117 |
|
| 118 | + def val_in_range(self, val): |
| 119 | + """ |
| 120 | + Return whether the value(s) are within the valid range for this scale. |
| 121 | +
|
| 122 | + This method is a generic implementation. Subclasses may implement more |
| 123 | + efficient solutions for their domain. |
| 124 | + """ |
| 125 | + try: |
| 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 |
| 131 | + except (TypeError, ValueError): |
| 132 | + return False |
| 133 | + |
117 | 134 |
|
118 | 135 | def _make_axis_parameter_optional(init_func): |
119 | 136 | """ |
@@ -196,6 +213,14 @@ def get_transform(self): |
196 | 213 | """ |
197 | 214 | return IdentityTransform() |
198 | 215 |
|
| 216 | + def val_in_range(self, val): |
| 217 | + """ |
| 218 | + Return whether the value is within the valid range for this scale. |
| 219 | +
|
| 220 | + This is True for all values, except +-inf and NaN. |
| 221 | + """ |
| 222 | + return math.isfinite(val) |
| 223 | + |
199 | 224 |
|
200 | 225 | class FuncTransform(Transform): |
201 | 226 | """ |
@@ -400,6 +425,14 @@ def limit_range_for_scale(self, vmin, vmax, minpos): |
400 | 425 | return (minpos if vmin <= 0 else vmin, |
401 | 426 | minpos if vmax <= 0 else vmax) |
402 | 427 |
|
| 428 | + def val_in_range(self, val): |
| 429 | + """ |
| 430 | + Return whether the value is within the valid range for this scale. |
| 431 | +
|
| 432 | + This is True for value(s) > 0 except +inf and NaN. |
| 433 | + """ |
| 434 | + return math.isfinite(val) and val > 0 |
| 435 | + |
403 | 436 |
|
404 | 437 | class FuncScaleLog(LogScale): |
405 | 438 | """ |
@@ -581,6 +614,14 @@ def get_transform(self): |
581 | 614 | """Return the `.SymmetricalLogTransform` associated with this scale.""" |
582 | 615 | return self._transform |
583 | 616 |
|
| 617 | + def val_in_range(self, val): |
| 618 | + """ |
| 619 | + Return whether the value is within the valid range for this scale. |
| 620 | +
|
| 621 | + This is True for all values, except +-inf and NaN. |
| 622 | + """ |
| 623 | + return math.isfinite(val) |
| 624 | + |
584 | 625 |
|
585 | 626 | class AsinhTransform(Transform): |
586 | 627 | """Inverse hyperbolic-sine transformation used by `.AsinhScale`""" |
@@ -707,6 +748,14 @@ def set_default_locators_and_formatters(self, axis): |
707 | 748 | else: |
708 | 749 | axis.set_major_formatter('{x:.3g}') |
709 | 750 |
|
| 751 | + def val_in_range(self, val): |
| 752 | + """ |
| 753 | + Return whether the value is within the valid range for this scale. |
| 754 | +
|
| 755 | + This is True for all values, except +-inf and NaN. |
| 756 | + """ |
| 757 | + return math.isfinite(val) |
| 758 | + |
710 | 759 |
|
711 | 760 | class LogitTransform(Transform): |
712 | 761 | input_dims = output_dims = 1 |
@@ -820,6 +869,14 @@ def limit_range_for_scale(self, vmin, vmax, minpos): |
820 | 869 | return (minpos if vmin <= 0 else vmin, |
821 | 870 | 1 - minpos if vmax >= 1 else vmax) |
822 | 871 |
|
| 872 | + def val_in_range(self, val): |
| 873 | + """ |
| 874 | + Return whether the value is within the valid range for this scale. |
| 875 | +
|
| 876 | + This is True for value(s) which are between 0 and 1 (excluded). |
| 877 | + """ |
| 878 | + return 0 < val < 1 |
| 879 | + |
823 | 880 |
|
824 | 881 | _scale_mapping = { |
825 | 882 | 'linear': LinearScale, |
|
0 commit comments