How to use the proplot.constructor.Locator function in proplot

To help you get started, we’ve selected a few proplot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lukelbd / proplot / proplot / axes / plot.py View on Github external
if isinstance(norm, mcolors.BoundaryNorm):
        # Get levels from bounds
        # TODO: Test this feature?
        # NOTE: No warning because we get here internally?
        levels = norm.boundaries
    elif np.iterable(values):
        # Prefer ticks in center
        ticks = np.asarray(values)
    elif np.iterable(levels):
        # Prefer ticks on level edges
        ticks = np.asarray(levels)
    else:
        # Determine levels automatically
        N = levels
        if locator is not None:
            locator = constructor.Locator(locator, **locator_kw)
            ticks = locator
        elif isinstance(norm, mcolors.LogNorm):
            locator = mticker.LogLocator(**locator_kw)
            ticks = locator
        elif isinstance(norm, mcolors.SymLogNorm):
            locator_kw.setdefault('linthresh', norm.linthresh)
            locator = mticker.SymmetricalLogLocator(**locator_kw)
            ticks = locator
        else:
            locator_kw.setdefault('symmetric', symmetric)
            locator = mticker.MaxNLocator(N, min_n_ticks=1, **locator_kw)

        # Get locations
        automin = vmin is None
        automax = vmax is None
        if automin or automax:
github lukelbd / proplot / proplot / axes / geo.py View on Github external
self._lataxis.set_latmax(latmax)

            # Update major locators
            lonlocator = _not_none(lonlocator=lonlocator, lonlines=lonlines)
            latlocator = _not_none(latlocator=latlocator, latlines=latlines)
            if lonlocator is not None:
                lonlocator_kw = _not_none(
                    lonlocator_kw=lonlocator_kw, lonlines_kw=lonlines_kw, default={},
                )
                locator = constructor.Locator(lonlocator, **lonlocator_kw)
                self._lonaxis.set_major_locator(locator)
            if latlocator is not None:
                latlocator_kw = _not_none(
                    latlocator_kw=latlocator_kw, latlines_kw=latlines_kw, default={},
                )
                locator = constructor.Locator(latlocator, **latlocator_kw)
                self._lataxis.set_major_locator(locator)

            # Update minor locators
            lonminorlocator = _not_none(
                lonminorlocator=lonminorlocator, lonminorlines=lonminorlines
            )
            latminorlocator = _not_none(
                latminorlocator=latminorlocator, latminorlines=latminorlines
            )
            if lonminorlocator is not None:
                lonminorlocator_kw = _not_none(
                    lonminorlocator_kw=lonminorlocator_kw,
                    lonminorlines_kw=lonminorlines_kw,
                    default={},
                )
                locator = constructor.Locator(lonminorlocator, **lonminorlocator_kw)
github lukelbd / proplot / proplot / axes / cartesian.py View on Github external
)
                        if not minorlocator:
                            minorlocator = constructor.Locator('minor')
                    else:
                        minorlocator = constructor.Locator(
                            minorlocator, **minorlocator_kw
                        )
                    axis.set_minor_locator(minorlocator)
                    axis.isDefault_minloc = isdefault
                elif tickminor is not None and not tickminor:
                    # NOTE: Generally if you *enable* minor ticks on a dual
                    # axis, want to allow FuncScale updates to change the
                    # minor tick locators. If you *disable* minor ticks, do
                    # not want FuncScale applications to turn them on. So we
                    # allow below to set isDefault_minloc to False.
                    axis.set_minor_locator(constructor.Locator('null'))

                # Major formatter
                # NOTE: The only reliable way to disable ticks labels and then
                # restore them is by messing with the *formatter*, rather than
                # setting labelleft=False, labelright=False, etc.
                if (
                    formatter is not None
                    or tickrange is not None
                    or wraprange is not None
                ):
                    # Tick range
                    if tickrange is not None or wraprange is not None:
                        if formatter not in (None, 'auto'):
                            warnings._warn_proplot(
                                'The tickrange and autorange features require '
                                'proplot.AutoFormatter formatter. Overriding '
github lukelbd / proplot / proplot / axes / geo.py View on Github external
lonarray = self._to_label_array(lonlabels, lon=True)
            latarray = self._to_label_array(latlabels, lon=False)

            # Update 'maximum latitude'
            latmax = _not_none(latmax, rc.get('grid.latmax', context=True))
            if latmax is not None:
                self._lataxis.set_latmax(latmax)

            # Update major locators
            lonlocator = _not_none(lonlocator=lonlocator, lonlines=lonlines)
            latlocator = _not_none(latlocator=latlocator, latlines=latlines)
            if lonlocator is not None:
                lonlocator_kw = _not_none(
                    lonlocator_kw=lonlocator_kw, lonlines_kw=lonlines_kw, default={},
                )
                locator = constructor.Locator(lonlocator, **lonlocator_kw)
                self._lonaxis.set_major_locator(locator)
            if latlocator is not None:
                latlocator_kw = _not_none(
                    latlocator_kw=latlocator_kw, latlines_kw=latlines_kw, default={},
                )
                locator = constructor.Locator(latlocator, **latlocator_kw)
                self._lataxis.set_major_locator(locator)

            # Update minor locators
            lonminorlocator = _not_none(
                lonminorlocator=lonminorlocator, lonminorlines=lonminorlines
            )
            latminorlocator = _not_none(
                latminorlocator=latminorlocator, latminorlines=latminorlines
            )
            if lonminorlocator is not None:
github lukelbd / proplot / proplot / axes / cartesian.py View on Github external
axis.set_major_formatter(formatter)

                # Ensure no out-of-bounds ticks; set_smart_bounds() can fail
                # * Using set_bounds did not work, so instead just turn
                #   locators into fixed version.
                # * Most locators take no arguments in __call__, and some do
                #   not have tick_values method, so we just call them.
                if (
                    bounds is not None
                    or fixticks
                    or isinstance(formatter, mticker.FixedFormatter)
                    or axis.get_scale() == 'cutoff'
                ):
                    if bounds is None:
                        bounds = getattr(self, 'get_' + x + 'lim')()
                    locator = constructor.Locator([
                        x for x in axis.get_major_locator()()
                        if bounds[0] <= x <= bounds[1]
                    ])
                    axis.set_major_locator(locator)
                    locator = constructor.Locator([
                        x for x in axis.get_minor_locator()()
                        if bounds[0] <= x <= bounds[1]
                    ])
                    axis.set_minor_locator(locator)

            # Call parent
            if aspect is not None:
                self.set_aspect(aspect)
            super().format(**kwargs)
github lukelbd / proplot / proplot / axes / geo.py View on Github external
def __init__(self, axes, latmax=90, projection=None):
        # NOTE: Need to pass projection because lataxis/lonaxis are
        # initialized before geoaxes is initialized, because format() needs
        # the axes and format() is called by proplot.axes.Axes.__init__()
        self._latmax = latmax
        super().__init__(axes)
        if self._use_dms(projection):
            locator = formatter = 'dmslat'
        else:
            locator = formatter = 'deglat'
        self.set_major_formatter(constructor.Formatter(formatter), default=True)
        self.set_major_locator(constructor.Locator(locator), default=True)
        self.set_minor_locator(mticker.AutoMinorLocator(), default=True)
github lukelbd / proplot / proplot / axes / geo.py View on Github external
)
            if lonminorlocator is not None:
                lonminorlocator_kw = _not_none(
                    lonminorlocator_kw=lonminorlocator_kw,
                    lonminorlines_kw=lonminorlines_kw,
                    default={},
                )
                locator = constructor.Locator(lonminorlocator, **lonminorlocator_kw)
                self._lonaxis.set_minor_locator(locator)
            if latminorlocator is not None:
                latminorlocator_kw = _not_none(
                    latminorlocator_kw=latminorlocator_kw,
                    latminorlines_kw=latminorlines_kw,
                    default={},
                )
                locator = constructor.Locator(latminorlocator, **latminorlocator_kw)
                self._lataxis.set_minor_locator(locator)

            # Update formatters
            loninline = _not_none(loninline, rc.get('grid.loninline', context=True))
            latinline = _not_none(latinline, rc.get('grid.latinline', context=True))
            labelpad = _not_none(labelpad, rc.get('grid.pad', context=True))
            rotatelabels = _not_none(
                rotatelabels, rc.get('grid.rotatelabels', context=True)
            )
            dms = _not_none(dms, rc.get('grid.dmslabels', context=True))
            nsteps = _not_none(nsteps, rc.get('grid.nsteps', context=True))
            if lonformatter is not None:
                lonformatter_kw = lonformatter_kw or {}
                formatter = constructor.Formatter(lonformatter, **lonformatter_kw)
                self._lonaxis.set_major_formatter(formatter)
            if latformatter is not None:
github lukelbd / proplot / proplot / axes / cartesian.py View on Github external
kw['text'] = label
                if color:
                    kw['color'] = color
                kw.update(label_kw)
                if kw:  # NOTE: initially keep spanning labels off
                    self._update_axis_labels(x, **kw)

                # Major and minor locator
                # NOTE: Parts of API (dualxy) rely on minor tick toggling
                # preserving the isDefault_minloc setting. In future should
                # override the default matplotlib API minorticks_on!
                # NOTE: Unlike matplotlib API when "turning on" minor ticks
                # we *always* use the scale default, thanks to scale classes
                # refactoring with _ScaleBase. See Axes.minorticks_on.
                if locator is not None:
                    locator = constructor.Locator(locator, **locator_kw)
                    axis.set_major_locator(locator)
                    if isinstance(locator, mticker.IndexLocator):
                        tickminor = False  # 'index' minor ticks make no sense
                if minorlocator in (True, False):
                    warnings._warn_proplot(
                        f'You passed {x}minorticks={minorlocator}, but this '
                        'argument is used to specify tick *locations*. If '
                        'you just want to *toggle* minor ticks on and off, '
                        f'please use {x}tickminor=True or {x}tickminor=False.'
                    )
                    minorlocator = None
                if tickminor or minorlocator:
                    isdefault = minorlocator is None
                    if isdefault:
                        minorlocator = getattr(
                            axis._scale, '_default_minor_locator', None