8000 FIX: allow secondary axes minor locators to be set by jklymak · Pull Request #14447 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: allow secondary axes minor locators to be set #14447

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 20, 2019

Conversation

jklymak
Copy link
Member
@jklymak jklymak commented Jun 4, 2019

PR Summary

We set the scale for secondary_axis for each draw in case the parent scale has changed (i.e. from linear to log), but this means that we can't set the locators and formatters for the secondary axis. This change keeps track of the parent scale and only resets the locators and formatters if the parent scale changes.

Closes #14443

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mticker

fig, ax = plt.subplots(constrained_layout=True)
x = np.arange(0, 360, 1)
y = np.sin(2 * x * np.pi / 180)
ax.plot(x, y)
ax.set_xlabel('angle [degrees]')
ax.set_ylabel('signal')
ax.set_title('Sine wave')

def deg2rad(x):
    return x * np.pi / 180

def rad2deg(x):
    return x * 180 / np.pi

secax = ax.secondary_xaxis('top', functions=(deg2rad, rad2deg))
secax.set_xlabel('angle [rad]')

ax.minorticks_on()
secax.minorticks_on()

plt.show()

now works as expected...

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

10000

@jklymak jklymak marked this pull request as ready for review June 4, 2019 21:20
@tacaswell tacaswell added this to the v3.2.0 milestone Jun 8, 2019
@@ -272,6 +273,11 @@ def _set_scale(self):
if self._orientation == 'y':
pscale = self._parent.yaxis.get_scale()
set_scale = self.set_yscale
if pscale == self._parentscale:
Copy link
Member

Choose a reason for hiding this comment

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

do we want == or is here?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ==, get_scale returns a string. Well really we should retrieve the scale object rather than a scale string, but that's a separate issue...

Copy link
Member
@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

One minor comment, but otherwise 👍

@tacaswell
Copy link
Member

Milestoned as 3.2 as a new feature, but I also see the case that this is a bug-fix. I leave to @jklymak to decide.

@jklymak can self-merge this after re-milestoning.

@anntzer
Copy link
Contributor
anntzer commented Jun 20, 2019

Merging as 3.2, but @jklymak can backport to 3.1 if he wants :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Secondary axis does not show minor ticks.
4 participants
0