Skip to main content

Make figures with context managers in python: quicker, simpler, more readable.

Project description

Figurex

PyPi Version MIT License Read the Docs Issues
Make figures with context managers in python: quicker, simpler, more readable.

with Figure() as ax:
    ax.plot([1,2],[3,4])

Idea

Tired of lengthy matplotlib code just for simple plotting?

# How plotting used to be:
import matplotlib.pyplot as plt

fig, axes = plt.subplots(1,2, figsize=(4,5))
plt.set_title("My plot")
ax = axes[0]
ax.plot([1,2],[3,4])
ax = axes[1]
ax.plot([2,3],[4,5])
fig.savefig("file.png", bbox_inches='tight')
plt.show()

Beautify your daily work with shorter and more readable code:

# How plotting becomes with figurex:
from figurex import Figure, Panel

with Figure("My plot", layout=(1,2), size=(4,5), save="file.png"):
    with Panel() as ax:
        ax.plot([1,2],[3,4])
    with Panel() as ax:
        ax.plot([2,3],[4,5])

The Figure() environment generates the matplotlib-based figure and axes for you, and automatically shows, saves, and closes the figure when leaving the context. It is just a wrapper around standard matplotlib code, you can use ax to modify the plot as you would normally do. Extend it your way without limits!

Examples

Make a simple plot:

with Figure("A simple plot") as ax:
    ax.plot([1,2],[3,4])

A plot with two panels:

with Figure(layout=(1,2), size=(6,3)):
    with Panel("a) Magic") as ax:
        ax.plot([1,2],[3,4])
    with Panel("b) Reality", grid="") as ax:
        ax.plot([5,5],[6,4])

Save a plot into memory for later use (e.g. in FPDF):

with Figure("Tea party", show=False):
    with Panel() as ax:
        ax.plot([5,5],[6,4])
my_figure = Figure.as_object()
# <_io.BytesIO at 0x...>

Plotting maps:

from figurex.basemap import Basemap

with Figure(size=(3,3)):
    with Basemap("Germany", extent=(5,15,46,55), tiles="relief") as Map:
        x,y = Map(12.385, 51.331)
        Map.scatter(x, y,  marker="x", color="red", s=200)

Figurex examples

Documentation

A documentation and API reference can be found on ReadTheDocs:

Install

pip install figurex

If you want to use geospatial mapping features with Basemap or Cartopy, install the corresponding optional features:

pip install figurex[basemap]
pip install figurex[cartopy]

Requirements

  • python >3.9
  • numpy
  • matplotlib
  • basemap >=1.4.1 (optional)
  • cartopy >=0.23 (optional)
  • scipy (optional, required by cartopy)

Related

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

figurex-0.2.10.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

figurex-0.2.10-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file figurex-0.2.10.tar.gz.

File metadata

  • Download URL: figurex-0.2.10.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.11 Windows/10

File hashes

Hashes for figurex-0.2.10.tar.gz
Algorithm Hash digest
SHA256 780296fbf321b1a0752cadff9e972eaf38fdb6f137c744cedd1e7316a01502f1
MD5 65db1cc52e9d5dfc93ebff2b917a85b9
BLAKE2b-256 8ca9aded18c955745edf649c39d1dc3e8aeac38a937718b307cc6f7c6d4d26a8

See more details on using hashes here.

File details

Details for the file figurex-0.2.10-py3-none-any.whl.

File metadata

  • Download URL: figurex-0.2.10-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.11 Windows/10

File hashes

Hashes for figurex-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 0aa7ae6f98950a89d0309a73f785adf069375a356f076ab3eb4c1231b9bf3609
MD5 10596f43ecb690183a692d4de4b5ec3e
BLAKE2b-256 28c6f4be91293490c4afe56eef22d427edcb2aa45d56573fcddff58c311dd7c0

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