Welcome to MatplotFormatPi’s documentation!

Help with showing multiples of pi on Matplotlib plots.

Classes available format numbers as exact multiples of pi on plots instead of showing them as decimals.

The class MultiplePi contains the math and formatting to accomplish this. MultiplePi has methods to return a Locator and FuncFormatter for use on a plot. Ticks are placed at exact multiples and the exact multiples are shown on the plot.

Modules include:
matplot_fmt_pi.ticker

Contains MultiplePi class

Note

Matplotlib has a basic_units.py module that can do this, however, it can only do format multiples of pi/2. In addition, it forces use of its own cos, sin, etc. while this is far more extensible.

class matplot_fmt_pi.ticker.MultiplePi(denominator: int, base: float = 3.141592653589793, symbol: str = '\\pi')

Handle formatting of numbers as multiples of pi.

An instance can be constructed, then, the methods can be called and passed to the matplotlib formatting and locating methods.

denominator

The denominator of the multiples desired.

Type

int

base

Number to find multiples of, by default math.pi

Type

float, optional

symbol

Symbol to place in string of multiple, by default r”pi”

Type

str, optional

locator()

Return the locator instance

formatter()

Return the formatter instance

Example

>>> pi_controller = MultiplePi(3) # For pi/3 and multiples of
>>> # Will put ticks at multiples of pi/3
>>> axes_instance.set_major_locator(pi_controller.locator())
>>> # Turn values into the fraction
>>> axes_instance.set_major_formatter(pi_controller.formatter())

Note

The symbol is rendered inside a latex equation by matplotlib. Non-latex characters can also be used.

Set symbol to a different value when base is a different value. (ie. tau)

formatter() → matplotlib.ticker.FuncFormatter

Return the formatter for multiple ticks.

Returns

Used to insert the symbol into the multiples

Return type

FuncFormatter

locator() → matplotlib.ticker.MultipleLocator

Return the locator with ticks at multiples of base via denominator.

Returns

The object used to space the ticks

Return type

MultipleLocator

Indices and tables