From aa944db97b91e6677c46439f7cef8c14b47d0dba Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 11 Oct 2020 21:36:14 +0200 Subject: [PATCH 01/11] feat: Define new rcParam option for number of minor ticks Fixes #14233 --- lib/matplotlib/mpl-data/matplotlibrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/mpl-data/matplotlibrc b/lib/matplotlib/mpl-data/matplotlibrc index 578777167d6c..86f70a23dacd 100644 --- a/lib/matplotlib/mpl-data/matplotlibrc +++ b/lib/matplotlib/mpl-data/matplotlibrc @@ -489,6 +489,7 @@ #xtick.major.bottom: True # draw x axis bottom major ticks #xtick.minor.top: True # draw x axis top minor ticks #xtick.minor.bottom: True # draw x axis bottom minor ticks +#xtick.minor.ndivs: auto # number of minor ticks between the major ticks on x-axis #xtick.alignment: center # alignment of xticks #ytick.left: True # draw ticks on the left side @@ -510,6 +511,7 @@ #ytick.major.right: True # draw y axis right major ticks #ytick.minor.left: True # draw y axis left minor ticks #ytick.minor.right: True # draw y axis right minor ticks +#ytick.minor.ndivs: auto # number of minor ticks between the major ticks on y-axis #ytick.alignment: center_baseline # alignment of yticks From f35f5ef4167824fb816c4a3bab85d6bb8068d8e3 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 11 Oct 2020 21:37:51 +0200 Subject: [PATCH 02/11] feat: Define validator for non-negative numbers and number of minor ticks --- lib/matplotlib/rcsetup.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index b27ac35bcb4d..f9ac292e3488 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -568,6 +568,14 @@ def _validate_greaterequal0_lessequal1(s): raise RuntimeError(f'Value must be >=0 and <=1; got {s}') +def _validate_int_greaterequal0(s): + s = validate_int(s) + if s >= 0: + return s + else: + raise RuntimeError(f'Value must be >=0; got {s}') + + def validate_hatch(s): r""" Validate a hatch pattern. @@ -587,6 +595,23 @@ def validate_hatch(s): validate_dashlist = _listify_validator(validate_floatlist) +def _validate_minor_tick_ndivs(n): + """ + Validate ndiv parameter related with the minor ticks. + It controls the number of minor ticks to be placed between + two major ticks. + """ + if isinstance(n, str): + n = n.lower() + if n == 'auto': + return n + + raise ValueError("Value must be set to 'auto'") + else: + n = _validate_int_greaterequal0(n) + return n + + _prop_validators = { 'color': _listify_validator(validate_color_for_prop_cycle, allow_stringlist=True), @@ -1093,6 +1118,8 @@ def _convert_validator_spec(key, conv): "xtick.minor.bottom": validate_bool, # draw bottom minor xticks "xtick.major.top": validate_bool, # draw top major xticks "xtick.major.bottom": validate_bool, # draw bottom major xticks + "xtick.minor.ndivs": _validate_minor_tick_ndivs, + # number of minor xticks "xtick.labelsize": validate_fontsize, # fontsize of xtick labels "xtick.direction": ["out", "in", "inout"], # direction of xticks "xtick.alignment": ["center", "right", "left"], @@ -1114,6 +1141,8 @@ def _convert_validator_spec(key, conv): "ytick.minor.right": validate_bool, # draw right minor yticks "ytick.major.left": validate_bool, # draw left major yticks "ytick.major.right": validate_bool, # draw right major yticks + "ytick.minor.ndivs": _validate_minor_tick_ndivs, + # number of minor yticks "ytick.labelsize": validate_fontsize, # fontsize of ytick labels "ytick.direction": ["out", "in", "inout"], # direction of yticks "ytick.alignment": [ From b4a8f8d490c9febb4fe4f56652dfbbd69185c4dc Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 11 Oct 2020 21:49:56 +0200 Subject: [PATCH 03/11] feat: Update class AutoMinorLocator to include the option for number of minor ticks --- lib/matplotlib/ticker.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index a29343029f60..81976528eb30 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2869,7 +2869,8 @@ def __init__(self, n=None): major ticks; e.g., n=2 will place a single minor tick midway between major ticks. - If *n* is omitted or None, it will be set to 5 or 4. + If *n* is omitted or None, the value stored in rcParams will be used. + In case *n* is set to 'auto', it will be set to 4 or 5. """ self.ndivs = n @@ -2891,6 +2892,12 @@ def __call__(self): return [] if self.ndivs is None: + if self.axis.axis_name == 'x': + self.ndivs = mpl.rcParams['xtick.minor.ndivs'] + else: + self.ndivs = mpl.rcParams['ytick.minor.ndivs'] + + if self.ndivs == 'auto': majorstep_no_exponent = 10 ** (np.log10(majorstep) % 1) From 31f935a9c18ad5b082876882c36a712b715012a6 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 11 Oct 2020 21:50:34 +0200 Subject: [PATCH 04/11] test: Define tests for the number of minor ticks options --- lib/matplotlib/tests/test_ticker.py | 116 ++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 15981c4c9047..8a4d65bd47c2 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -211,6 +211,122 @@ def test_additional(self, lim, ref): assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + @pytest.mark.parametrize( + 'lim, ref', + [ + ( + (0, 1.39), + [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, + 0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9, + 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35] + ), + ( + (0, 0.139), + [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, + 0.05, 0.055, 0.065, 0.07, 0.075, 0.085, 0.09, + 0.095, 0.105, 0.11, 0.115, 0.125, 0.13, 0.135] + ), + ], + ) + def test_number_of_minor_ticks_rcparams_auto(self, lim, ref): + with mpl.rc_context({'xtick.minor.ndivs': 'auto', 'ytick.minor.ndivs': 'auto'}): + fig, ax = plt.subplots() + ax.set_xlim(*lim) + ax.set_ylim(*lim) + ax.xaxis.set_minor_locator(mticker.AutoMinorLocator()) + ax.yaxis.set_minor_locator(mticker.AutoMinorLocator()) + assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) + assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + + @pytest.mark.parametrize( + 'lim, ref', + [ + ( + (0, 1.39), + [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, + 0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9, + 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35] + ), + ( + (0, 0.139), + [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, + 0.05, 0.055, 0.065, 0.07, 0.075, 0.085, 0.09, + 0.095, 0.105, 0.11, 0.115, 0.125, 0.13, 0.135] + ), + ], + ) + def test_number_of_minor_ticks_ndivs_auto(self, lim, ref): + fig, ax = plt.subplots() + ax.set_xlim(*lim) + ax.set_ylim(*lim) + ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(n='auto')) + ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(n='auto')) + assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) + assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + + @pytest.mark.parametrize( + 'n, lim, ref', + [ + ( + 2, + (0, 4), + [0.5, 1.5, 2.5, 3.5] + ), + ( + 4, + (0, 2), + [0.25, 0.5, 0.75, 1.25, 1.5, 1.75] + ), + ( + 10, + (0, 1), + [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] + ), + ], + ) + def test_number_of_minor_ticks_rcparams_int(self, n, lim, ref): + with mpl.rc_context({'xtick.minor.ndivs': n, 'ytick.minor.ndivs': n}): + fig, ax = plt.subplots() + ax.set_xlim(*lim) + ax.set_ylim(*lim) + ax.xaxis.set_major_locator(mticker.MultipleLocator(1)) + ax.xaxis.set_minor_locator(mticker.AutoMinorLocator()) + ax.yaxis.set_major_locator(mticker.MultipleLocator(1)) + ax.yaxis.set_minor_locator(mticker.AutoMinorLocator()) + assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) + assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + + @pytest.mark.parametrize( + 'n, lim, ref', + [ + ( + 2, + (0, 4), + [0.5, 1.5, 2.5, 3.5] + ), + ( + 4, + (0, 2), + [0.25, 0.5, 0.75, 1.25, 1.5, 1.75] + ), + ( + 10, + (0, 1), + [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] + ), + ], + ) + def test_number_of_minor_ticks_ndivs_int(self, n, lim, ref): + fig, ax = plt.subplots() + ax.set_xlim(*lim) + ax.set_ylim(*lim) + ax.xaxis.set_major_locator(mticker.MultipleLocator(1)) + ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(n)) + ax.yaxis.set_major_locator(mticker.MultipleLocator(1)) + ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(n)) + assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) + assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + class TestLogLocator: def test_basic(self): From 6a4583a894d5c725117d063636365aa0a08795fe Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 14 Oct 2020 23:59:23 +0200 Subject: [PATCH 05/11] fix, refactor: Define a better minor tick ndivs validator --- lib/matplotlib/rcsetup.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index f9ac292e3488..726f8a948d8b 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -601,15 +601,16 @@ def _validate_minor_tick_ndivs(n): It controls the number of minor ticks to be placed between two major ticks. """ - if isinstance(n, str): - n = n.lower() - if n == 'auto': - return n - raise ValueError("Value must be set to 'auto'") - else: + if isinstance(n, str) and n.lower() == 'auto': + return n + try: n = _validate_int_greaterequal0(n) return n + except (RuntimeError, ValueError): + pass + + raise ValueError("'tick.minor.ndivs' must be a 'auto' or non-negative int") _prop_validators = { From 92548915eb4dba1bda573c26adf7d5fd87e3e826 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 15 Oct 2020 00:00:40 +0200 Subject: [PATCH 06/11] doc: Provide better documentation when ndiv is set to auto --- lib/matplotlib/ticker.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 81976528eb30..5376620b38cb 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2870,7 +2870,10 @@ def __init__(self, n=None): between major ticks. If *n* is omitted or None, the value stored in rcParams will be used. - In case *n* is set to 'auto', it will be set to 4 or 5. + In case *n* is set to 'auto', it will be set to 4 or 5. If the distance + between the major ticks equals 1, 2.5, 5 or 10 it can be perfectly + divided in 5 equidistant sub-intervals with a length multiple of + 0.05. Otherwise it is divided in 4 sub-intervals. """ self.ndivs = n From ddac5cb73f8cff5a74f53862ebdc77eb5e798386 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 16 Oct 2020 21:04:24 +0200 Subject: [PATCH 07/11] refactor, doc: Update documentation --- lib/matplotlib/rcsetup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 726f8a948d8b..663ff4b70536 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -597,7 +597,7 @@ def validate_hatch(s): def _validate_minor_tick_ndivs(n): """ - Validate ndiv parameter related with the minor ticks. + Validate ndiv parameter related to the minor ticks. It controls the number of minor ticks to be placed between two major ticks. """ @@ -610,7 +610,7 @@ def _validate_minor_tick_ndivs(n): except (RuntimeError, ValueError): pass - raise ValueError("'tick.minor.ndivs' must be a 'auto' or non-negative int") + raise ValueError("'tick.minor.ndivs' must be 'auto' or non-negative int") _prop_validators = { @@ -1119,8 +1119,8 @@ def _convert_validator_spec(key, conv): "xtick.minor.bottom": validate_bool, # draw bottom minor xticks "xtick.major.top": validate_bool, # draw top major xticks "xtick.major.bottom": validate_bool, # draw bottom major xticks - "xtick.minor.ndivs": _validate_minor_tick_ndivs, # number of minor xticks + "xtick.minor.ndivs": _validate_minor_tick_ndivs, "xtick.labelsize": validate_fontsize, # fontsize of xtick labels "xtick.direction": ["out", "in", "inout"], # direction of xticks "xtick.alignment": ["center", "right", "left"], @@ -1142,8 +1142,8 @@ def _convert_validator_spec(key, conv): "ytick.minor.right": validate_bool, # draw right minor yticks "ytick.major.left": validate_bool, # draw left major yticks "ytick.major.right": validate_bool, # draw right major yticks - "ytick.minor.ndivs": _validate_minor_tick_ndivs, # number of minor yticks + "ytick.minor.ndivs": _validate_minor_tick_ndivs, "ytick.labelsize": validate_fontsize, # fontsize of ytick labels "ytick.direction": ["out", "in", "inout"], # direction of yticks "ytick.alignment": [ From 13cd5fe14e4492a54812379758f32cc8e1d0b8e9 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 16 Oct 2020 21:04:52 +0200 Subject: [PATCH 08/11] fix: Handle the z-axis case --- lib/matplotlib/ticker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 5376620b38cb..bf059567f5fe 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2895,10 +2895,12 @@ def __call__(self): return [] if self.ndivs is None: - if self.axis.axis_name == 'x': - self.ndivs = mpl.rcParams['xtick.minor.ndivs'] - else: + + if self.axis.axis_name == 'y': self.ndivs = mpl.rcParams['ytick.minor.ndivs'] + else: + # for x and z axis + self.ndivs = mpl.rcParams['xtick.minor.ndivs'] if self.ndivs == 'auto': From 24f71f159b9fb7af5326d7002f209da0f8d130f4 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 16 Oct 2020 21:05:52 +0200 Subject: [PATCH 09/11] feat, refactor: Combine rcparams and kwargs in one test suite --- lib/matplotlib/tests/test_ticker.py | 144 +++++++++------------------- 1 file changed, 45 insertions(+), 99 deletions(-) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 8a4d65bd47c2..3a1fc1db3c82 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -212,121 +212,67 @@ def test_additional(self, lim, ref): assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) @pytest.mark.parametrize( - 'lim, ref', - [ - ( - (0, 1.39), - [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, - 0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9, - 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35] - ), - ( - (0, 0.139), - [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, - 0.05, 0.055, 0.065, 0.07, 0.075, 0.085, 0.09, - 0.095, 0.105, 0.11, 0.115, 0.125, 0.13, 0.135] - ), - ], - ) - def test_number_of_minor_ticks_rcparams_auto(self, lim, ref): - with mpl.rc_context({'xtick.minor.ndivs': 'auto', 'ytick.minor.ndivs': 'auto'}): + 'lim, ref, use_rcparam', [ + ((0, 1.39), + [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.65, 0.7, + 0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35], True), + ((0, 1.39), + [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.65, 0.7, + 0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35], False), + ((0, 0.139), + [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, 0.05, 0.055, + 0.065, 0.07, 0.075, 0.085, 0.09, 0.095, 0.105, 0.11, 0.115, + 0.125, 0.13, 0.135], True), + ((0, 0.139), + [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, 0.05, 0.055, + 0.065, 0.07, 0.075, 0.085, 0.09, 0.095, 0.105, 0.11, 0.115, + 0.125, 0.13, 0.135], False), + ]) + def test_number_of_minor_ticks_auto(self, lim, ref, use_rcparam): + if use_rcparam: + context = {'xtick.minor.ndivs': 'auto', 'ytick.minor.ndivs': 'auto'} + kwargs = {} + else: + context = {} + kwargs = {'n': 'auto'} + + with mpl.rc_context(context): fig, ax = plt.subplots() ax.set_xlim(*lim) ax.set_ylim(*lim) - ax.xaxis.set_minor_locator(mticker.AutoMinorLocator()) - ax.yaxis.set_minor_locator(mticker.AutoMinorLocator()) + ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs)) + ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs)) assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) @pytest.mark.parametrize( - 'lim, ref', - [ - ( - (0, 1.39), - [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, - 0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9, - 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35] - ), - ( - (0, 0.139), - [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, - 0.05, 0.055, 0.065, 0.07, 0.075, 0.085, 0.09, - 0.095, 0.105, 0.11, 0.115, 0.125, 0.13, 0.135] - ), - ], - ) - def test_number_of_minor_ticks_ndivs_auto(self, lim, ref): - fig, ax = plt.subplots() - ax.set_xlim(*lim) - ax.set_ylim(*lim) - ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(n='auto')) - ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(n='auto')) - assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) - assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + 'n, lim, ref, use_rcparam', [ + (2, (0, 4), [0.5, 1.5, 2.5, 3.5], True), + (2, (0, 4), [0.5, 1.5, 2.5, 3.5], False), + (4, (0, 2), [0.25, 0.5, 0.75, 1.25, 1.5, 1.75], True), + (4, (0, 2), [0.25, 0.5, 0.75, 1.25, 1.5, 1.75], False), + (10, (0, 1), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], True), + (10, (0, 1), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], False), + ]) + def test_number_of_minor_ticks_int(self, n, lim, ref, use_rcparam): + if use_rcparam: + context = {'xtick.minor.ndivs': n, 'ytick.minor.ndivs': n} + kwargs = {} + else: + context = {} + kwargs = {'n': n} - @pytest.mark.parametrize( - 'n, lim, ref', - [ - ( - 2, - (0, 4), - [0.5, 1.5, 2.5, 3.5] - ), - ( - 4, - (0, 2), - [0.25, 0.5, 0.75, 1.25, 1.5, 1.75] - ), - ( - 10, - (0, 1), - [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] - ), - ], - ) - def test_number_of_minor_ticks_rcparams_int(self, n, lim, ref): - with mpl.rc_context({'xtick.minor.ndivs': n, 'ytick.minor.ndivs': n}): + with mpl.rc_context(context): fig, ax = plt.subplots() ax.set_xlim(*lim) ax.set_ylim(*lim) ax.xaxis.set_major_locator(mticker.MultipleLocator(1)) - ax.xaxis.set_minor_locator(mticker.AutoMinorLocator()) + ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs)) ax.yaxis.set_major_locator(mticker.MultipleLocator(1)) - ax.yaxis.set_minor_locator(mticker.AutoMinorLocator()) + ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(**kwargs)) assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) - @pytest.mark.parametrize( - 'n, lim, ref', - [ - ( - 2, - (0, 4), - [0.5, 1.5, 2.5, 3.5] - ), - ( - 4, - (0, 2), - [0.25, 0.5, 0.75, 1.25, 1.5, 1.75] - ), - ( - 10, - (0, 1), - [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] - ), - ], - ) - def test_number_of_minor_ticks_ndivs_int(self, n, lim, ref): - fig, ax = plt.subplots() - ax.set_xlim(*lim) - ax.set_ylim(*lim) - ax.xaxis.set_major_locator(mticker.MultipleLocator(1)) - ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(n)) - ax.yaxis.set_major_locator(mticker.MultipleLocator(1)) - ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(n)) - assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) - assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) - class TestLogLocator: def test_basic(self): From 3c36a5047638de4b5ae8076c2085e543bb3d9cea Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 17 Oct 2020 09:27:30 +0200 Subject: [PATCH 10/11] refactor: Take out use_rcparam in separate parametrizing --- lib/matplotlib/tests/test_ticker.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 3a1fc1db3c82..3d38df575f09 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -211,22 +211,16 @@ def test_additional(self, lim, ref): assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + @pytest.mark.parametrize('use_rcparam', [False, True]) @pytest.mark.parametrize( - 'lim, ref, use_rcparam', [ + 'lim, ref', [ ((0, 1.39), [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.65, 0.7, - 0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35], True), - ((0, 1.39), - [0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45, 0.5, 0.55, 0.65, 0.7, - 0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35], False), - ((0, 0.139), - [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, 0.05, 0.055, - 0.065, 0.07, 0.075, 0.085, 0.09, 0.095, 0.105, 0.11, 0.115, - 0.125, 0.13, 0.135], True), + 0.75, 0.85, 0.9, 0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35]), ((0, 0.139), [0.005, 0.01, 0.015, 0.025, 0.03, 0.035, 0.045, 0.05, 0.055, 0.065, 0.07, 0.075, 0.085, 0.09, 0.095, 0.105, 0.11, 0.115, - 0.125, 0.13, 0.135], False), + 0.125, 0.13, 0.135]), ]) def test_number_of_minor_ticks_auto(self, lim, ref, use_rcparam): if use_rcparam: @@ -245,14 +239,12 @@ def test_number_of_minor_ticks_auto(self, lim, ref, use_rcparam): assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), ref) assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref) + @pytest.mark.parametrize('use_rcparam', [False, True]) @pytest.mark.parametrize( - 'n, lim, ref, use_rcparam', [ - (2, (0, 4), [0.5, 1.5, 2.5, 3.5], True), - (2, (0, 4), [0.5, 1.5, 2.5, 3.5], False), - (4, (0, 2), [0.25, 0.5, 0.75, 1.25, 1.5, 1.75], True), - (4, (0, 2), [0.25, 0.5, 0.75, 1.25, 1.5, 1.75], False), - (10, (0, 1), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], True), - (10, (0, 1), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], False), + 'n, lim, ref', [ + (2, (0, 4), [0.5, 1.5, 2.5, 3.5]), + (4, (0, 2), [0.25, 0.5, 0.75, 1.25, 1.5, 1.75]), + (10, (0, 1), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]), ]) def test_number_of_minor_ticks_int(self, n, lim, ref, use_rcparam): if use_rcparam: From 970938b9c677c4313cc886733b5f1e8415bdbfa7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 13 May 2023 03:58:07 -0400 Subject: [PATCH 11/11] DOC: Add what's new for AutoMinorLocator rcParams --- doc/users/next_whats_new/auto_minor_tick.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/users/next_whats_new/auto_minor_tick.rst diff --git a/doc/users/next_whats_new/auto_minor_tick.rst b/doc/users/next_whats_new/auto_minor_tick.rst new file mode 100644 index 000000000000..02db8f6beb38 --- /dev/null +++ b/doc/users/next_whats_new/auto_minor_tick.rst @@ -0,0 +1,5 @@ +rcParams for ``AutoMinorLocator`` divisions +------------------------------------------- +The rcParams :rc:`xtick.minor.ndivs` and :rc:`ytick.minor.ndivs` have been +added to enable setting the default number of divisions; if set to ``auto``, +the number of divisions will be chosen by the distance between major ticks.