Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a transformation to secondary_xaxis/_yaxis #25224

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ZachDaChampion
Copy link

@ZachDaChampion ZachDaChampion commented Feb 15, 2023

PR Summary

resolves #25119.

I'm new to Matplotlib development so not sure if this is the best way to do this. I added a transform parameter to secondary_xaxis and secondary_yaxis and passed that through into SecondaryAxis._set_location(), where the transform is blended.

if self._orientation == 'x':
    # An x-secondary axes is like an inset axes from x = 0 to x = 1 and
    # from y = pos to y = pos + eps, in the parent's transAxes coords.
    bounds = [0, self._pos, 1., 1e-10]

    # If a transformation is provided, use its y component rather than
    # the parent's transAxes. This can be used to place axes in the data
    # coords, for instance.
    if transform is not None:
        transform = transforms.blended_transform_factory(
            self._parent.transAxes, transform)
else:  # 'y'
    bounds = [self._pos, 0, 1e-10, 1]
    if transform is not None:
        transform = transforms.blended_transform_factory(
            transform, self._parent.transAxes)  # Use provided x axis

# If no transform is provided, use the parent's transAxes
if transform is None:
    transform = self._parent.transAxes

I also updated test_secondary_xy() and test_secondary_fail() to test the transform.

I'm not entirely sure if/where I'm meant to put .. versionchanged:: in the docsting, but I'm happy to add it if it's needed.

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
    • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@jklymak
Copy link
Member

jklymak commented Feb 15, 2023

This looks really useful, and a quick glance the code is great. Can we add an example, at least in the issue that shows the usefulness of this? Probably want one in the example gallery as well. I had to read your code to understand the context here, which if I understand is to allow the secondary xaxis to have a y position specified in data co-ordinates rather than just axes co-ordinates.

If that is the case, what happens if the y data limits are set so the secondary axis is out of the Axes viewport?

@jklymak jklymak changed the title Allow passing a transformation to a secondary plot Allow passing a transformation to secondary_xaxis/_yaxis Feb 15, 2023
@ZachDaChampion
Copy link
Author

@jklymak Yes, you are correct on the context. Right now, if an axis is out of the viewport it isn't drawn. The existing function behaves the same if you give it a location outside of the viewport. E.g. x2 = ax.secondary_xaxis(1.5) is not drawn. If we want it to do something else I'd be happy to change it.

Good point on the examples, I'll take care of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[ENH]: secondary_x/yaxis accept transform argument
2 participants