FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix/restore secondary axis support for Transform-type functions by zachjweiner · Pull Request #27267 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .png  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions lib/matplotlib/axes/_secondary_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import matplotlib.ticker as mticker
from matplotlib.axes._base import _AxesBase, _TransformedBoundsLocator
from matplotlib.axis import Axis
from matplotlib.transforms import Transform


class SecondaryAxis(_AxesBase):
Expand Down Expand Up @@ -144,11 +145,17 @@ def set_functions(self, functions):
If a transform is supplied, then the transform must have an
inverse.
"""

if (isinstance(functions, tuple) and len(functions) == 2 and
callable(functions[0]) and callable(functions[1])):
# make an arbitrary convert from a two-tuple of functions
# forward and inverse.
self._functions = functions
elif isinstance(functions, Transform):
self._functions = (
functions.transform,
lambda x: functions.inverted().transform(x)
)
elif functions is None:
self._functions = (lambda x: x, lambda x: x)
else:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7494,6 +7494,20 @@ def test_annotate_across_transforms():
arrowprops=dict(arrowstyle="->"))


class _Translation(mtransforms.Transform):
Comment thread
QuLogic marked this conversation as resolved.
input_dims = 1
output_dims = 1

def __init__(self, dx):
self.dx = dx

def transform(self, values):
return values + self.dx

def inverted(self):
return _Translation(-self.dx)


@image_comparison(['secondary_xy.png'], style='mpl20')
def test_secondary_xy():
fig, axs = plt.subplots(1, 2, figsize=(10, 5), constrained_layout=True)
Expand All @@ -7513,6 +7527,7 @@ def invert(x):
secax(0.4, functions=(lambda x: 2 * x, lambda x: x / 2))
secax(0.6, functions=(lambda x: x**2, lambda x: x**(1/2)))
secax(0.8)
secax("top" if nn == 0 else "right", functions=_Translation(2))


def test_secondary_fail():
Expand Down

Back | FazBrowse Home | New Git URL