@@ -1195,13 +1195,23 @@ def altx(self, **kwargs):
1195
1195
"""
1196
1196
%(axes.altx)s
1197
1197
"""
1198
- # Cannot wrap twiny() because we want to use CartesianAxes, not
1199
- # matplotlib Axes. Instead use hidden method _make_twin_axes.
1200
- # See https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_subplots.py # noqa
1198
+ # NOTE: Cannot *wrap* twiny() because we want to use CartesianAxes, not
1199
+ # matplotlib Axes. Instead use hidden method SubplotBase._make_twin_axes.
1200
+ # WARNING: This repairs a matplotlib bug where twins fail to inherit the minor
1201
+ # locator due to application of `AutoMinorLocator` when `ytick.minor.visible`
1202
+ # is ``True`` in `Axes.cla` and due to the fact that passing ``sharey=self``
1203
+ # to the alternate axes means that they share the same major and minor Tickers.
1204
+ # >>> import matplotlib.pyplot as plt
1205
+ # ... fig, ax = plt.subplots()
1206
+ # ... ax.set_yscale('log')
1207
+ # ... ax.twiny()
1201
1208
if self ._altx_child or self ._altx_parent :
1202
1209
raise RuntimeError ('No more than *two* twin axes are allowed.' )
1203
1210
with self .figure ._context_authorize_add_subplot ():
1211
+ ylocator = self .yaxis .get_minor_locator ()
1204
1212
ax = self ._make_twin_axes (sharey = self , projection = 'cartesian' )
1213
+ ax .yaxis .set_minor_locator (ylocator )
1214
+ ax .yaxis .isDefault_minloc = True
1205
1215
ax .set_autoscaley_on (self .get_autoscaley_on ())
1206
1216
ax .grid (False )
1207
1217
self ._altx_child = ax
@@ -1218,11 +1228,14 @@ def alty(self, **kwargs):
1218
1228
"""
1219
1229
%(axes.alty)s
1220
1230
"""
1221
- # Docstring is programatically assigned below
1231
+ # See altx() comments
1222
1232
if self ._alty_child or self ._alty_parent :
1223
1233
raise RuntimeError ('No more than *two* twin axes are allowed.' )
1224
1234
with self .figure ._context_authorize_add_subplot ():
1235
+ xlocator = self .xaxis .get_minor_locator ()
1225
1236
ax = self ._make_twin_axes (sharex = self , projection = 'cartesian' )
1237
+ ax .xaxis .set_minor_locator (xlocator )
1238
+ ax .xaxis .isDefault_minloc = True
1226
1239
ax .set_autoscalex_on (self .get_autoscalex_on ())
1227
1240
ax .grid (False )
1228
1241
self ._alty_child = ax
0 commit comments