Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Allow passing a transformation to secondary_xaxis/_yaxis#25224
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletionsgalleries/examples/subplots_axes_and_figures/secondary_axis.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
52 changes: 38 additions & 14 deletionslib/matplotlib/axes/_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 |
---|---|---|
@@ -551,7 +551,7 @@ def indicate_inset_zoom(self, inset_ax, **kwargs): | ||
return self.indicate_inset(rect, inset_ax, **kwargs) | ||
@_docstring.dedent_interpd | ||
def secondary_xaxis(self, location, *, functions=None,transform=None,**kwargs): | ||
timhoffm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
""" | ||
Add a second x-axis to this `~.axes.Axes`. | ||
@@ -582,18 +582,30 @@ def invert(x): | ||
secax = ax.secondary_xaxis('top', functions=(invert, invert)) | ||
secax.set_xlabel('Period [s]') | ||
plt.show() | ||
To add a secondary axis relative to your data, you can pass a transform | ||
to the new axis. | ||
ZachDaChampion marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
.. plot:: | ||
fig, ax = plt.subplots() | ||
ax.plot(range(0, 5), range(-1, 4)) | ||
# Pass 'ax.transData' as a transform to place the axis | ||
# relative to your data at y=0 | ||
secax = ax.secondary_xaxis(0, transform=ax.transData) | ||
""" | ||
if not (location in ['top', 'bottom'] or isinstance(location, Real)): | ||
raise ValueError('secondary_xaxis location must be either ' | ||
'a float or "top"/"bottom"') | ||
secondary_ax = SecondaryAxis(self, 'x', location, functions, | ||
transform, **kwargs) | ||
self.add_child_axes(secondary_ax) | ||
return secondary_ax | ||
@_docstring.dedent_interpd | ||
def secondary_yaxis(self, location, *, functions=None,transform=None,**kwargs): | ||
timhoffm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
""" | ||
Add a second y-axis to this `~.axes.Axes`. | ||
@@ -614,16 +626,28 @@ def secondary_yaxis(self, location, *, functions=None, **kwargs): | ||
secax = ax.secondary_yaxis('right', functions=(np.deg2rad, | ||
np.rad2deg)) | ||
secax.set_ylabel('radians') | ||
To add a secondary axis relative to your data, you can pass a transform | ||
to the new axis. | ||
.. plot:: | ||
fig, ax = plt.subplots() | ||
ax.plot(range(0, 5), range(-1, 4)) | ||
# Pass 'ax.transData' as a transform to place the axis | ||
# relative to your data at x=3 | ||
secax = ax.secondary_yaxis(3, transform=ax.transData) | ||
""" | ||
if not (location in ['left', 'right'] or isinstance(location, Real)): | ||
raise ValueError('secondary_yaxis location must be either ' | ||
'a float or "left"/"right"') | ||
secondary_ax = SecondaryAxis(self, 'y', location, functions, | ||
transform, **kwargs) | ||
self.add_child_axes(secondary_ax) | ||
return secondary_ax | ||
@_docstring.dedent_interpd | ||
def text(self, x, y, s, fontdict=None, **kwargs): | ||
""" | ||
2 changes: 2 additions & 0 deletionslib/matplotlib/axes/_axes.pyi
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
43 changes: 37 additions & 6 deletionslib/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
5 changes: 4 additions & 1 deletionlib/matplotlib/axes/_secondary_axes.pyi
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
Binary file modifiedlib/matplotlib/tests/baseline_images/test_axes/secondary_xy.png
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletionslib/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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.