From c9bc9bc94900a4152faf509fc828bd2e26181d27 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 4 Jun 2019 13:08:50 -0700 Subject: [PATCH 1/2] FIX: allow secondary axes minor locators to be set --- lib/matplotlib/axes/_secondary_axes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/matplotlib/axes/_secondary_axes.py b/lib/matplotlib/axes/_secondary_axes.py index 4740fe6b23fb..b9ae2d57d6a3 100644 --- a/lib/matplotlib/axes/_secondary_axes.py +++ b/lib/matplotlib/axes/_secondary_axes.py @@ -82,6 +82,7 @@ def __init__(self, parent, orientation, self._axis = self.yaxis self._locstrings = ['right', 'left'] self._otherstrings = ['top', 'bottom'] + self._parentscale = self._axis.get_scale() # this gets positioned w/o constrained_layout so exclude: self._layoutbox = None self._poslayoutbox = None @@ -272,6 +273,11 @@ def _set_scale(self): if self._orientation == 'y': pscale = self._parent.yaxis.get_scale() set_scale = self.set_yscale + if pscale == self._parentscale: + return + else: + self._parentscale = pscale + if pscale == 'log': defscale = 'functionlog' else: From ca90947d15f11d967c5b4698320577c3f921bc77 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 4 Jun 2019 13:59:31 -0700 Subject: [PATCH 2/2] TST: changing scale and locators secondary axis --- lib/matplotlib/tests/test_axes.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 9e1a8c8123d8..9c3570c2bc16 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -24,6 +24,7 @@ import matplotlib.markers as mmarkers import matplotlib.patches as mpatches import matplotlib.colors as mcolors +import matplotlib.ticker as mticker import matplotlib.transforms as mtransforms from numpy.testing import ( assert_allclose, assert_array_equal, assert_array_almost_equal) @@ -6079,6 +6080,29 @@ def invert(x): assert_allclose(ax.get_position().extents, [0.125, 0.1, 0.9, 0.9]) +def test_secondary_minorloc(): + fig, ax = plt.subplots(figsize=(10, 5)) + ax.plot(np.arange(2, 11), np.arange(2, 11)) + def invert(x): + with np.errstate(divide='ignore'): + return 1 / x + + secax = ax.secondary_xaxis('top', functions=(invert, invert)) + assert isinstance(secax._axis.get_minor_locator(), + mticker.NullLocator) + secax.minorticks_on() + assert isinstance(secax._axis.get_minor_locator(), + mticker.AutoMinorLocator) + ax.set_xscale('log') + plt.draw() + assert isinstance(secax._axis.get_minor_locator(), + mticker.LogLocator) + ax.set_xscale('linear') + plt.draw() + assert isinstance(secax._axis.get_minor_locator(), + mticker.NullLocator) + + def color_boxes(fig, axs): """ Helper for the tests below that test the extents of various axes elements 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