Skip to main content

Format numbers as multiples of Pi

Project description

Matplotlib Format Pi

Upload Python Package

Create locator and formatter instances for multiples of pi on the axes of a matplotlib graph.

The MultiplePi class provides methods to seamlessly tell matplotlib to format tick labels as multiples of pi.

In addition, the MultiplePi class allows a user to change the denominator of the base provided.

Multiples of π/2, 3, 4, ... can be represented if needed.

Examples

Simply, the instance can be asssigned a denominator of pi then passed to matplotlib.

import matplotlib.pyplot as plt
import numpy as np

from matplot_fmt_pi import MultiplePi

fig = plt.figure(figsize=(4*np.pi, 2.4))
axes = fig.add_subplot(111)
x = np.linspace(-2*np.pi, 2*np.pi, 512)
axes.plot(x, np.sin(x))

axes.grid(True)
axes.axhline(0, color='black', lw=2)
axes.axvline(0, color='black', lw=2)
axes.set_title("MultiplePi formatting")

pi_manager = MultiplePi(2)
axes.xaxis.set_major_locator(pi_manager.locator())
axes.xaxis.set_major_formatter(pi_manager.formatter())

plt.tight_layout()
plt.show()

The parameters can also be modified to adjust the output to something more sophisticated.

import matplotlib.pyplot as plt
import numpy as np

from matplot_fmt_pi import MultiplePi

fig = plt.figure()
axes = fig.add_subplot(111)
tau = np.pi*2
x = np.linspace(-tau/60, tau*8/60, 512)
axes.plot(x, np.exp(-x)*np.cos(60*x))

axes.grid(True)
axes.axhline(0, color='black', lw=2)
axes.axvline(0, color='black', lw=2)
axes.set_title("MultiplePi formatting")

major_pi_manager = MultiplePi(60, base=tau, symbol=r"\tau")
minor_pi_manager = MultiplePi(240, base=tau, symbol=r"\tau")

axes.xaxis.set_major_locator(major_pi_manager.locator())
axes.xaxis.set_major_formatter(major_pi_manager.formatter())
axes.xaxis.set_minor_locator(minor_pi_manager.locator())

plt.tight_layout()
plt.show()

Meta

Inspired by this post on StackOverflow.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matplot-fmt-pi-1.4.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

matplot_fmt_pi-1.4.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file matplot-fmt-pi-1.4.0.tar.gz.

File metadata

  • Download URL: matplot-fmt-pi-1.4.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for matplot-fmt-pi-1.4.0.tar.gz
Algorithm Hash digest
SHA256 8a3b665566fe24a679c07384f77b0dde13de04d187f07c4c9d3defc2dfeea6bf
MD5 3f6911e2780984b412fe21d68c2c9e5c
BLAKE2b-256 1d51cdce65d474f0f75efcbbf866c54cd2bca17a1e84d7af6d253207979d6bcc

See more details on using hashes here.

File details

Details for the file matplot_fmt_pi-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: matplot_fmt_pi-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for matplot_fmt_pi-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a18867cebb56bd179d5e84a71bed08ba6324150cf06a4bd7a678f57dfa54b87a
MD5 2a471a280d66d324735612485ff019a3
BLAKE2b-256 6e2e646ff2147c00d33d3526ff7ead8db0ba1be356afee0c8f9459cb55d343e6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page