Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: allow secondary axes to be non-linear #14640

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

Merged
merged 2 commits into from
Jun 28, 2019

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jun 27, 2019

PR Summary

Fixes an issue on gitter by @Tillsten whereby the secondary_axes doesn't do ticks properly for non-linear axes.

The issue here is that we really need to use the inverse to position ticks, not the forward function:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.01, 90, 91)

def xsq(x):
    return((x)**2)

def sqx(x):
    return(np.sqrt(x))

fig, ax  = plt.subplots(1, 1, figsize=(4, 3), constrained_layout=True)
ax.plot(sqx(x), x)
ax.set_ylim([0.001, 90])
secax = ax.secondary_yaxis('right', functions=(sqx, xsq))
plt.draw()
ax.set_xlabel("$x^{1/2}$")
ax.set_ylabel("x")
plt.show()

Before

This is what we would want a sqrt(x) scale to normally look like....

Before

After

... but for a secondary axis we want the values to match up, so we really need to specify the position with the inverse:

second

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak force-pushed the fix-non-linear-secondary-axis branch 3 times, most recently from 86829ea to 489587d Compare June 27, 2019 04:56
Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Clearly the ticks were wrong and are now correct...
This is borderline 3.1.1 material?

@jklymak jklymak force-pushed the fix-non-linear-secondary-axis branch from 489587d to c373535 Compare June 27, 2019 13:55
@jklymak jklymak added this to the v3.1.1 milestone Jun 27, 2019
@jklymak jklymak added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jun 27, 2019
@jklymak
Copy link
Member Author

jklymak commented Jun 27, 2019

Not super concerned if its not in for 3.1.1., but lets see if it gets in.

@jklymak
Copy link
Member Author

jklymak commented Jun 27, 2019

Appveyor failure seems unrelated....

@ivanov ivanov merged commit f9e71a5 into matplotlib:master Jun 28, 2019
@ivanov
Copy link
Member

ivanov commented Jun 28, 2019

thanks @jklymak and @anntzer

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jun 28, 2019
ivanov added a commit that referenced this pull request Jun 28, 2019
…640-on-v3.1.x

Backport PR #14640 on branch v3.1.x (FIX: allow secondary axes to be non-linear)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants