From cef2d95f7ed4c8ee97c986cc6adce403f2d06115 Mon Sep 17 00:00:00 2001 From: pharshalp Date: Mon, 10 Feb 2020 19:11:34 -0500 Subject: [PATCH] fix colorbar minorticks when rcParams['x/ytick.minor.visible'] = True Added a test Replaced the unnecessary logic with a one liner as suggested Better docs for test Removed random data from test flake8 fix --- lib/matplotlib/colorbar.py | 4 ++++ lib/matplotlib/tests/test_colorbar.py | 28 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 9e0110343e49..eb9511e0bb38 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -517,8 +517,12 @@ def _config_axis(self): if self.orientation == 'vertical': long_axis, short_axis = ax.yaxis, ax.xaxis + if mpl.rcParams['ytick.minor.visible']: + self.minorticks_on() else: long_axis, short_axis = ax.xaxis, ax.yaxis + if mpl.rcParams['xtick.minor.visible']: + self.minorticks_on() long_axis.set_label_position(self.ticklocation) long_axis.set_ticks_position(self.ticklocation) diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index 3ef5cbee62a6..eb2044e2f97d 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -327,6 +327,34 @@ def test_colorbar_minorticks_on_off(): np.testing.assert_equal(cbar.ax.yaxis.get_minorticklocs(), []) +def test_cbar_minorticks_for_rc_xyminortickvisible(): + """ + issue gh-16468. + + Making sure that minor ticks on the colorbar are turned on + (internally) using the cbar.minorticks_on() method when + rcParams['xtick.minor.visible'] = True (for horizontal cbar) + rcParams['ytick.minor.visible'] = True (for vertical cbar). + Using cbar.minorticks_on() ensures that the minor ticks + don't overflow into the extend regions of the colorbar. + """ + + plt.rcParams['ytick.minor.visible'] = True + plt.rcParams['xtick.minor.visible'] = True + + vmin, vmax = 0.4, 2.6 + fig, ax = plt.subplots() + im = ax.pcolormesh([[1, 2]], vmin=vmin, vmax=vmax) + + cbar = fig.colorbar(im, extend='both', orientation='vertical') + assert cbar.ax.yaxis.get_minorticklocs()[0] >= vmin + assert cbar.ax.yaxis.get_minorticklocs()[-1] <= vmax + + cbar = fig.colorbar(im, extend='both', orientation='horizontal') + assert cbar.ax.xaxis.get_minorticklocs()[0] >= vmin + assert cbar.ax.xaxis.get_minorticklocs()[-1] <= vmax + + def test_colorbar_autoticks(): # Test new autotick modes. Needs to be classic because # non-classic doesn't go this route. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy