faninsar.plots.formatters.PiFormatter#

class faninsar.plots.formatters.PiFormatter(denominator: int = 4, symbol: str | None = None, use_unicode: bool = True, latex: bool = False)[source]#

Bases: Formatter

Format axis tick labels as multiples of π.

This formatter displays values in terms of π, making it easier to read phase values that are naturally expressed in radians.

__init__(denominator: int = 4, symbol: str | None = None, use_unicode: bool = True, latex: bool = False) None[source]#

Initialize the formatter.

Parameters:
  • denominator (int, optional) – The maximum denominator for fraction simplification. Default is 4.

  • symbol (str, optional) – The symbol to use for pi. Default is ‘π’. Can also use ‘pi’. When latex is True, the default symbol becomes "\\pi".

  • use_unicode (bool, optional) – Whether to use Unicode π symbol (default) or ‘pi’ string. Ignored when latex is True and symbol is not provided.

  • latex (bool, optional) – Whether to return labels wrapped in mathtext (LaTeX) for improved rendering. Default is False.

Examples

>>> import matplotlib.pyplot as plt
>>> from faninsar.plots import PiFormatter, PiLocator
>>> fig, ax = plt.subplots()
>>> ax.xaxis.set_major_formatter(PiFormatter())
>>> ax.xaxis.set_major_locator(PiLocator())

Methods

__init__([denominator, symbol, use_unicode, ...])

Initialize the formatter.

create_dummy_axis(**kwargs)

fix_minus(s)

Some classes may want to replace a hyphen for minus with the proper Unicode symbol (U+2212) for typographical correctness. This is a helper method to perform such a replacement when it is enabled via :rc:`axes.unicode_minus`.

format_data(value)

Return the full string representation of the value with the position unspecified.

format_data_short(value)

Return a short string version of the tick value.

format_ticks(values)

Return the tick labels for all the ticks at once.

get_offset()

set_axis(axis)

set_locs(locs)

Set the locations of the ticks.

Attributes

static fix_minus(s)#

Some classes may want to replace a hyphen for minus with the proper Unicode symbol (U+2212) for typographical correctness. This is a helper method to perform such a replacement when it is enabled via :rc:`axes.unicode_minus`.

create_dummy_axis(**kwargs)#
format_data(value)#

Return the full string representation of the value with the position unspecified.

format_data_short(value)#

Return a short string version of the tick value.

Defaults to the position-independent long value.

format_ticks(values)#

Return the tick labels for all the ticks at once.

get_offset()#
set_axis(axis)#
set_locs(locs)#

Set the locations of the ticks.

This method is called before computing the tick labels because some formatters need to know all tick locations to do so.

axis = None#
locs = []#