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

Skip to content

Commit b53418e

Browse files
authored
FIX: allow secondary axes minor locators to be set (#14447)
FIX: allow secondary axes minor locators to be set
2 parents 63d96d2 + ca90947 commit b53418e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/matplotlib/axes/_secondary_axes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def __init__(self, parent, orientation,
8282
self._axis = self.yaxis
8383
self._locstrings = ['right', 'left']
8484
self._otherstrings = ['top', 'bottom']
85+
self._parentscale = self._axis.get_scale()
8586
# this gets positioned w/o constrained_layout so exclude:
8687
self._layoutbox = None
8788
self._poslayoutbox = None
@@ -272,6 +273,11 @@ def _set_scale(self):
272273
if self._orientation == 'y':
273274
pscale = self._parent.yaxis.get_scale()
274275
set_scale = self.set_yscale
276+
if pscale == self._parentscale:
277+
return
278+
else:
279+
self._parentscale = pscale
280+
275281
if pscale == 'log':
276282
defscale = 'functionlog'
277283
else:

lib/matplotlib/tests/test_axes.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import matplotlib.markers as mmarkers
2525
import matplotlib.patches as mpatches
2626
import matplotlib.colors as mcolors
27+
import matplotlib.ticker as mticker
2728
import matplotlib.transforms as mtransforms
2829
from numpy.testing import (
2930
assert_allclose, assert_array_equal, assert_array_almost_equal)
@@ -6111,6 +6112,29 @@ def invert(x):
61116112
assert_allclose(ax.get_position().extents, [0.125, 0.1, 0.9, 0.9])
61126113

61136114

6115+
def test_secondary_minorloc():
6116+
fig, ax = plt.subplots(figsize=(10, 5))
6117+
ax.plot(np.arange(2, 11), np.arange(2, 11))
6118+
def invert(x):
6119+
with np.errstate(divide='ignore'):
6120+
return 1 / x
6121+
6122+
secax = ax.secondary_xaxis('top', functions=(invert, invert))
6123+
assert isinstance(secax._axis.get_minor_locator(),
6124+
mticker.NullLocator)
6125+
secax.minorticks_on()
6126+
assert isinstance(secax._axis.get_minor_locator(),
6127+
mticker.AutoMinorLocator)
6128+
ax.set_xscale('log')
6129+
plt.draw()
6130+
assert isinstance(secax._axis.get_minor_locator(),
6131+
mticker.LogLocator)
6132+
ax.set_xscale('linear')
6133+
plt.draw()
6134+
assert isinstance(secax._axis.get_minor_locator(),
6135+
mticker.NullLocator)
6136+
6137+
61146138
def color_boxes(fig, axs):
61156139
"""
61166140
Helper for the tests below that test the extents of various axes elements

0 commit comments

Comments
 (0)