Example #1
0
    def test_minor(self, lims, expected_low_ticks):
        """
        In large scale, test the presence of minor,
        and assert no minor when major are subsampled.
        """

        expected_ticks = sorted(
            [*expected_low_ticks, 0.5, *(1 - expected_low_ticks)]
        )
        basic_needed = len(expected_ticks)
        loc = mticker.LogitLocator(nbins=100)
        minor_loc = mticker.LogitLocator(nbins=100, minor=True)
        for nbins in range(basic_needed, 2, -1):
            loc.set_params(nbins=nbins)
            minor_loc.set_params(nbins=nbins)
            major_ticks = loc.tick_values(*lims)
            minor_ticks = minor_loc.tick_values(*lims)
            if len(major_ticks) >= len(expected_ticks):
                # no subsample, we must have a lot of minors ticks
                assert (len(major_ticks) - 1) * 5 < len(minor_ticks)
            else:
                # subsample
                _LogitHelper.assert_almost_equal(
                    np.sort(np.concatenate((major_ticks, minor_ticks))),
                    expected_ticks,
                )
Example #2
0
 def __init__(self, **kwargs):
     """
     Parameters
     ----------
     nonpos : {'mask', 'clip'}
       Values outside of (0, 1) can be masked as invalid, or clipped to a
       number very close to 0 or 1.
     """
     super().__init__(**kwargs)
     # self._default_major_formatter = mticker.LogitFormatter()
     self._default_major_locator = mticker.LogitLocator()
     self._default_minor_locator = mticker.LogitLocator(minor=True)
Example #3
0
 def test_minor_attr(self):
     loc = mticker.LogitLocator(nbins=100)
     assert not loc.minor
     loc.minor = True
     assert loc.minor
     loc.set_params(minor=False)
     assert not loc.minor
Example #4
0
 def test_set_params(self):
     """
     Create logit locator with default minor=False, and change it to
     something else. See if change was successful. Should not exception.
     """
     loc = mticker.LogitLocator()  # Defaults to false.
     loc.set_params(minor=True)
     assert loc.minor
Example #5
0
 def test_nonsingular_ok(self, lims):
     """
     Create logit locator, and test the nonsingular method for acceptable
     value
     """
     loc = mticker.LogitLocator()
     lims2 = loc.nonsingular(*lims)
     assert sorted(lims) == sorted(lims2)
Example #6
0
 def test_basic_major(self, lims, expected_low_ticks):
     """
     Create logit locator with huge number of major, and tests ticks.
     """
     expected_ticks = sorted(
         [*expected_low_ticks, 0.5, *(1 - expected_low_ticks)])
     loc = mticker.LogitLocator(nbins=100)
     _LogitHelper.assert_almost_equal(loc.tick_values(*lims),
                                      expected_ticks)
Example #7
0
    def test_nbins_major(self, lims):
        """
        Assert logit locator for respecting nbins param.
        """

        basic_needed = int(-np.floor(np.log10(lims[0]))) * 2 + 1
        loc = mticker.LogitLocator(nbins=100)
        for nbins in range(basic_needed, 2, -1):
            loc.set_params(nbins=nbins)
            assert len(loc.tick_values(*lims)) <= nbins + 2
Example #8
0
 def test_minor_number(self):
     """
     Test the parameter minor_number
     """
     min_loc = mticker.LogitLocator(minor=True)
     min_form = mticker.LogitFormatter(minor=True)
     ticks = min_loc.tick_values(5e-2, 1 - 5e-2)
     for minor_number in (2, 4, 8, 16):
         min_form.set_minor_number(minor_number)
         formatted = min_form.format_ticks(ticks)
         labelled = [f for f in formatted if len(f) > 0]
         assert len(labelled) == minor_number
    def _clear(self):

        self._raw.set_major_locator(ticker.AutoLocator())
        self._raw.set_minor_locator(ticker.NullLocator())

        if self._scale == Scale.Log:
            self._raw.set_major_locator(ticker.LogLocator())
            self._raw.set_minor_locator(ticker.LogLocator(subs="auto"))
        elif self._scale == Scale.Logit:
            self._raw.set_major_locator(ticker.LogitLocator())
        elif self._scale == Scale.SymmetricLog:
            self._raw.set_major_locator(ticker.SymmetricalLogLocator())
Example #10
0
 def test_nonsingular_nok(self, okval):
     """
     Create logit locator, and test the nonsingular method for non
     acceptable value
     """
     loc = mticker.LogitLocator()
     vmin, vmax = (-1, okval)
     vmin2, vmax2 = loc.nonsingular(vmin, vmax)
     assert vmax2 == vmax
     assert 0 < vmin2 < vmax2
     vmin, vmax = (okval, 2)
     vmin2, vmax2 = loc.nonsingular(vmin, vmax)
     assert vmin2 == vmin
     assert vmin2 < vmax2 < 1
Example #11
0
 def test_maxn_major(self, lims):
     """
     When the axis is zoomed, the locator must have the same behavior as
     MaxNLocator.
     """
     loc = mticker.LogitLocator(nbins=100)
     maxn_loc = mticker.MaxNLocator(nbins=100, steps=[1, 2, 5, 10])
     for nbins in (4, 8, 16):
         loc.set_params(nbins=nbins)
         maxn_loc.set_params(nbins=nbins)
         ticks = loc.tick_values(*lims)
         maxn_ticks = maxn_loc.tick_values(*lims)
         assert ticks.shape == maxn_ticks.shape
         assert (ticks == maxn_ticks).all()
Example #12
0
    def test_minor_vs_major(self, method, lims, cases):
        """
        Test minor/major displays.
        """

        if method:
            min_loc = mticker.LogitLocator(minor=True)
            ticks = min_loc.tick_values(*lims)
        else:
            ticks = np.array(lims)
        min_form = mticker.LogitFormatter(minor=True)
        for threshold, has_minor in cases:
            min_form.set_minor_threshold(threshold)
            formatted = min_form.format_ticks(ticks)
            labelled = [f for f in formatted if len(f) > 0]
            if has_minor:
                assert len(labelled) > 0, (threshold, has_minor)
            else:
                assert len(labelled) == 0, (threshold, has_minor)