From b6fd4e5217a8e5d4ad8139cf00f382ebaf3b6243 Mon Sep 17 00:00:00 2001 From: ImportanceOfBeingErnest Date: Thu, 6 Dec 2018 02:33:32 +0100 Subject: [PATCH] tickminorvisible-fix --- lib/matplotlib/scale.py | 3 ++- lib/matplotlib/tests/test_ticker.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index 21fe910c57b0..9dfe696d1176 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -69,7 +69,8 @@ def set_default_locators_and_formatters(self, axis): axis.set_major_formatter(ScalarFormatter()) axis.set_minor_formatter(NullFormatter()) # update the minor locator for x and y axis based on rcParams - if rcParams['xtick.minor.visible']: + if (axis.axis_name == 'x' and rcParams['xtick.minor.visible'] + or axis.axis_name == 'y' and rcParams['ytick.minor.visible']): axis.set_minor_locator(AutoMinorLocator()) else: axis.set_minor_locator(NullLocator()) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 5a7b8f446349..f499e5b7de07 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -851,3 +851,21 @@ def test_minlocator_type(): fig, ax = plt.subplots() with pytest.raises(TypeError): ax.xaxis.set_minor_locator(matplotlib.ticker.LogFormatter()) + + +def test_minorticks_rc(): + fig = plt.figure() + + def minorticksubplot(xminor, yminor, i): + rc = {'xtick.minor.visible': xminor, + 'ytick.minor.visible': yminor} + with plt.rc_context(rc=rc): + ax = fig.add_subplot(2, 2, i) + + assert (len(ax.xaxis.get_minor_ticks()) > 0) == xminor + assert (len(ax.yaxis.get_minor_ticks()) > 0) == yminor + + minorticksubplot(False, False, 1) + minorticksubplot(True, False, 2) + minorticksubplot(False, True, 3) + minorticksubplot(True, True, 4)