Skip to main content

Wrapper for Matplotlib.

Project description

shplot

shplot is a Python library wrapper for managing Matplotlib configuration through profiles, and provides a number of built-in profiles suitable for different use cases.

Installation

shplot is available on PyPI, and can be installed with pip:

pip install shplot

Usage

Common use cases are shown here. Refer to the documentation for in-depth usage. The project repository's demos/ folder contains illustrations of the built-in profiles. The demo files can be (re)generated by running scripts/plot_demos.py.

Create a plot and use it in a context

>>> from shplot import ShPlot
>>> plot = ShPlot(builtin_profile_name="paper")
>>> with plot.context(nrows=2, ncols=2) as (fig, axs):
...     # `axs` is a 2x2 array.
...     pass
>>> with plot.context(mosaic="AAB\nC.B") as (fig, axs):
...     # `axs` is a dictionary.
...     pass

Update Matplotlib settings using a profile

>>> from shplot.profiles import ColorProfile
>>> profile = ColorProfile(fg="yellow", bg="black")
>>> profile.config()  # will update `matplotlib.rcParams`

Use a built-in profile with overrides

>>> from shplot import ShPlot
>>> from shplot.profiles.builtin import ShPaperProfile
>>> profile = ShPaperProfile(fontname="fira", **{"axes.grid": True})
>>> profile.config()

Create a plot using command line arguments

main.py

from shplot import ShPlot

plot = ShPlot.parse_from_cmdline()
with plot.context() as (fig, ax):
    ...
$ python main.py -h
usage: main.py [-h] [--file str] [--shprofile str] [--profile-args key=val,...] [--width
  float] [--aspect float[;float]]

options:
  -h/--help                   show this help message and exit
  --file str                  Plot save file (extension will be added if not provided).
                              (optional)
  --shprofile str             Name of a built-in profile.
                              ({paper/book/web_light/web_dark/presentation} optional)
  --profile-args key=val,...  Arguments for the builtin-profile. Refer to the individual
                              profiles for details. (optional)
  --width float               Plot width, in inches (if greater than 1), or as a fraction of
                              the configured plot width (if less than or equal to 1).
                              (optional)
  --aspect float[;float]      Plot aspect ratio, width/height. When provided as a command
                              line argument, can be passed as a single number or a ratio in
                              the form `<WIDTH>;<HEIGHT>`. (optional)

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

shplot-1.0.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shplot-1.0.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file shplot-1.0.0.tar.gz.

File metadata

  • Download URL: shplot-1.0.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1022-azure

File hashes

Hashes for shplot-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f6396fcbcbbeb82e0055b905959100c44abb91c7015c3a411e09ebcdf1436736
MD5 4f73f9c11e6098f068a0c5f6f0efa30c
BLAKE2b-256 f8cb0ce629e3f0feb5257c9b08d814bc2fcf2819765480487dfcf2e538f12c39

See more details on using hashes here.

File details

Details for the file shplot-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: shplot-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1022-azure

File hashes

Hashes for shplot-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec928e8461a63edf10ed478f34a67180bd6440d502f788fd014c5bc615f53be8
MD5 fe6dff3f3a5fe141e3e1c296971f0c64
BLAKE2b-256 26807ba19721ddad524bc79b77ad6b98d4dda51e68299e72b6d7735b5243b8fe

See more details on using hashes here.

Supported by

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