faninsar.plots.formatters.PiLocator#

class faninsar.plots.formatters.PiLocator(base: float = 0.5)[source]#

Bases: Locator

Locate tick positions at multiples of π.

This locator places ticks at nice intervals based on π, making it easier to read phase plots.

__init__(base: float = 0.5) None[source]#

Initialize the locator.

Parameters:

base (float, optional) – The base multiple of π for tick spacing. Default is 0.5 (π/2). Common values are 1.0 (π), 0.5 (π/2), 0.25 (π/4).

Examples

>>> import matplotlib.pyplot as plt
>>> from faninsar.plots import PiFormatter, PiLocator
>>> fig, ax = plt.subplots()
>>> ax.xaxis.set_major_locator(PiLocator(base=0.5))  # Ticks at multiples of π/2
>>> ax.xaxis.set_major_formatter(PiFormatter())

Methods

__init__([base])

Initialize the locator.

create_dummy_axis(**kwargs)

nonsingular(v0, v1)

Adjust a range as needed to avoid singularities.

raise_if_exceeds(locs)

Log at WARNING level if locs is longer than Locator.MAXTICKS.

set_axis(axis)

set_params(**kwargs)

Do nothing, and raise a warning.

tick_values(vmin, vmax)

Return tick values within the given range.

view_limits(dmin, dmax)

Set the view limits to nice values around the data range.

Attributes

create_dummy_axis(**kwargs)#
nonsingular(v0, v1)#

Adjust a range as needed to avoid singularities.

This method gets called during autoscaling, with (v0, v1) set to the data limits on the Axes if the Axes contains any data, or (-inf, +inf) if not.

  • If v0 == v1 (possibly up to some floating point slop), this method returns an expanded interval around this value.

  • If (v0, v1) == (-inf, +inf), this method returns appropriate default view limits.

  • Otherwise, (v0, v1) is returned without modification.

raise_if_exceeds(locs)#

Log at WARNING level if locs is longer than Locator.MAXTICKS.

This is intended to be called immediately before returning locs from __call__ to inform users in case their Locator returns a huge number of ticks, causing Matplotlib to run out of memory.

The “strange” name of this method dates back to when it would raise an exception instead of emitting a log.

set_axis(axis)#
set_params(**kwargs)#

Do nothing, and raise a warning. Any locator class not supporting the set_params() function will call this.

tick_values(vmin: float, vmax: float) NDArray[np.floating][source]#

Return tick values within the given range.

Parameters:
  • vmin (float) – Minimum value of the axis range.

  • vmax (float) – Maximum value of the axis range.

Returns:

Array of tick locations.

Return type:

array

view_limits(dmin: float, dmax: float) tuple[float, float][source]#

Set the view limits to nice values around the data range.

Parameters:
  • dmin (float) – Minimum data value.

  • dmax (float) – Maximum data value.

Returns:

Nice view limits (vmin, vmax).

Return type:

tuple

MAXTICKS = 1000#
axis = None#