Skip to content

Commit 2f64361

Browse files
committed
Fix mpl bug where altx/y resets log minor locator
1 parent 2cb5a5b commit 2f64361

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

proplot/axes/cartesian.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,13 +1195,23 @@ def altx(self, **kwargs):
11951195
"""
11961196
%(axes.altx)s
11971197
"""
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()
12011208
if self._altx_child or self._altx_parent:
12021209
raise RuntimeError('No more than *two* twin axes are allowed.')
12031210
with self.figure._context_authorize_add_subplot():
1211+
ylocator = self.yaxis.get_minor_locator()
12041212
ax = self._make_twin_axes(sharey=self, projection='cartesian')
1213+
ax.yaxis.set_minor_locator(ylocator)
1214+
ax.yaxis.isDefault_minloc = True
12051215
ax.set_autoscaley_on(self.get_autoscaley_on())
12061216
ax.grid(False)
12071217
self._altx_child = ax
@@ -1218,11 +1228,14 @@ def alty(self, **kwargs):
12181228
"""
12191229
%(axes.alty)s
12201230
"""
1221-
# Docstring is programatically assigned below
1231+
# See altx() comments
12221232
if self._alty_child or self._alty_parent:
12231233
raise RuntimeError('No more than *two* twin axes are allowed.')
12241234
with self.figure._context_authorize_add_subplot():
1235+
xlocator = self.xaxis.get_minor_locator()
12251236
ax = self._make_twin_axes(sharex=self, projection='cartesian')
1237+
ax.xaxis.set_minor_locator(xlocator)
1238+
ax.xaxis.isDefault_minloc = True
12261239
ax.set_autoscalex_on(self.get_autoscalex_on())
12271240
ax.grid(False)
12281241
self._alty_child = ax

proplot/axes/plot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,15 @@ def standardize_1d(self, func, *args, autoformat=None, **kwargs):
522522
if label and not getattr(self, f'get_{iname}label')():
523523
# For histograms, this label is used for *x* coordinates
524524
kw[iname + 'label'] = label
525-
# Xlabel
526525
if name not in ('hist',):
526+
# Xlabel
527527
x, label = _axis_labels_title(x)
528528
if label and not getattr(self, f'get_{xname}label')():
529529
kw[xname + 'label'] = label
530-
# Reversed axis
531-
if name not in ('scatter',) and len(x) > 1 and xi is None and x[1] < x[0]:
532-
kw[xname + 'reverse'] = True
530+
# Reversed axis
531+
if name not in ('scatter',):
532+
if len(x) > 1 and xi is None and x[1] < x[0]:
533+
kw[xname + 'reverse'] = True
533534

534535
# Appply
535536
if kw:

0 commit comments

Comments
 (0)