diff --git a/doc/users/whats_new/rcparams.rst b/doc/users/whats_new/rcparams.rst index 7111a6e6c215..4e7d367c46cb 100644 --- a/doc/users/whats_new/rcparams.rst +++ b/doc/users/whats_new/rcparams.rst @@ -1,3 +1,9 @@ +Added ``xtick.minor.visible`` and ``ytick.minor.visible`` key to rcParams +````````````````````````````````````````````````````````````````````````` +Two new keys to control the minor ticks on x/y axis respectively, default set to ``False`` (no minor ticks on the axis). + +When ``True``, the minor ticks are shown and located via a ``mticker.AutoMinorLocator()``. + Added "legend.framealpha" key to rcParams ````````````````````````````````````````` Added a key and the corresponding logic to control the default transparency of diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e7b9696947c9..4765e76a54a5 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -881,6 +881,13 @@ def cla(self): else: self.yaxis._set_scale('linear') + # update the minor locator for x and y axis based on rcParams + if (rcParams['xtick.minor.visible']): + self.xaxis.set_minor_locator(mticker.AutoMinorLocator()) + + if (rcParams['ytick.minor.visible']): + self.yaxis.set_minor_locator(mticker.AutoMinorLocator()) + self._autoscaleXon = True self._autoscaleYon = True self._xmargin = rcParams['axes.xmargin'] diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index b25788da001e..2c24ad25b2e0 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -694,6 +694,8 @@ def __call__(self, s): 'xtick.major.pad': [4, validate_float], # distance to label in points 'xtick.minor.pad': [4, validate_float], # distance to label in points 'xtick.color': ['k', validate_color], # color of the xtick labels + 'xtick.minor.visible': [False, validate_bool], # visiablility of the x axis minor ticks + # fontsize of the xtick labels 'xtick.labelsize': ['medium', validate_fontsize], 'xtick.direction': ['in', six.text_type], # direction of xticks @@ -705,6 +707,8 @@ def __call__(self, s): 'ytick.major.pad': [4, validate_float], # distance to label in points 'ytick.minor.pad': [4, validate_float], # distance to label in points 'ytick.color': ['k', validate_color], # color of the ytick labels + 'ytick.minor.visible': [False, validate_bool], # visiablility of the y axis minor ticks + # fontsize of the ytick labels 'ytick.labelsize': ['medium', validate_fontsize], 'ytick.direction': ['in', six.text_type], # direction of yticks diff --git a/lib/matplotlib/tests/baseline_images/test_axes/minorticks_on_rcParams_both.png b/lib/matplotlib/tests/baseline_images/test_axes/minorticks_on_rcParams_both.png new file mode 100644 index 000000000000..42fc1debbd12 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/minorticks_on_rcParams_both.png differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index db170440d221..d931ca031afc 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -129,6 +129,17 @@ def test_twinx_cla(): assert_true(ax.yaxis.get_visible()) +@image_comparison(baseline_images=["minorticks_on_rcParams_both"], extensions=['png']) +def test_minorticks_on_rcParams_both(): + + fig = plt.figure() + matplotlib.rcParams['xtick.minor.visible'] = True + matplotlib.rcParams['ytick.minor.visible'] = True + + plt.plot([0, 1], [0, 1]) + plt.axis([0, 1, 0, 1]) + + @image_comparison(baseline_images=["autoscale_tiny_range"], remove_text=True) def test_autoscale_tiny_range(): # github pull #904