| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | import matplotlib.ticker as mticker | |
| 7 | 7 | from matplotlib.axes._base import _AxesBase, _TransformedBoundsLocator | |
| 8 | 8 | from matplotlib.axis import Axis | |
| 9 | + from matplotlib.transforms import Transform | ||
| 9 | 10 | ||
| 10 | 11 | ||
| 11 | 12 | class SecondaryAxis(_AxesBase): | |
@@ -144,11 +145,17 @@ def set_functions(self, functions): | |||
| 144 | 145 | If a transform is supplied, then the transform must have an | |
| 145 | 146 | inverse. | |
| 146 | 147 | """ | |
| 148 | + | ||
| 147 | 149 | if (isinstance(functions, tuple) and len(functions) == 2 and | |
| 148 | 150 | callable(functions[0]) and callable(functions[1])): | |
| 149 | 151 | # make an arbitrary convert from a two-tuple of functions | |
| 150 | 152 | # forward and inverse. | |
| 151 | 153 | self._functions = functions | |
| 154 | + elif isinstance(functions, Transform): | ||
| 155 | + self._functions = ( | ||
| 156 | + functions.transform, | ||
| 157 | + lambda x: functions.inverted().transform(x) | ||
| 158 | + ) | ||
| 152 | 159 | elif functions is None: | |
| 153 | 160 | self._functions = (lambda x: x, lambda x: x) | |
| 154 | 161 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7509,6 +7509,20 @@ def test_annotate_across_transforms(): | |||
| 7509 | 7509 | arrowprops=dict(arrowstyle="->")) | |
| 7510 | 7510 | ||
| 7511 | 7511 | ||
| 7512 | + class _Translation(mtransforms.Transform): | ||
| 7513 | + input_dims = 1 | ||
| 7514 | + output_dims = 1 | ||
| 7515 | + | ||
| 7516 | + def __init__(self, dx): | ||
| 7517 | + self.dx = dx | ||
| 7518 | + | ||
| 7519 | + def transform(self, values): | ||
| 7520 | + return values + self.dx | ||
| 7521 | + | ||
| 7522 | + def inverted(self): | ||
| 7523 | + return _Translation(-self.dx) | ||
| 7524 | + | ||
| 7525 | + | ||
| 7512 | 7526 | @image_comparison(['secondary_xy.png'], style='mpl20') | |
| 7513 | 7527 | def test_secondary_xy(): | |
| 7514 | 7528 | fig, axs = plt.subplots(1, 2, figsize=(10, 5), constrained_layout=True) | |
@@ -7528,6 +7542,7 @@ def invert(x): | |||
| 7528 | 7542 | secax(0.4, functions=(lambda x: 2 * x, lambda x: x / 2)) | |
| 7529 | 7543 | secax(0.6, functions=(lambda x: x**2, lambda x: x**(1/2))) | |
| 7530 | 7544 | secax(0.8) | |
| 7545 | + secax("top" if nn == 0 else "right", functions=_Translation(2)) | ||
| 7531 | 7546 | ||
| 7532 | 7547 | ||
| 7533 | 7548 | def test_secondary_fail(): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments