Skip to main content

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

Project description

Figurex

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 pyplot

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", save="memory") as memory:
    with Panel() as ax:
        ax.plot([5,5],[6,4])
memory
# <_io.BytesIO at 0x...>

Plotting maps:

from figurex 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)

Install

pip install figurex

Requirements

  • Minimal requirements (basic plotting):
    • python >3.9
    • numpy
    • matplotlib
  • If you want to make geographic maps with figurex.cartopy:
    • cartopy
  • If you want to make geographic maps with figurex.basemap:
    • basemap >1.4

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.1.5.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

figurex-0.1.5-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: figurex-0.1.5.tar.gz
  • Upload date:
  • Size: 21.1 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.1.5.tar.gz
Algorithm Hash digest
SHA256 1ef6ccfc1bd4959e8bf9381d3c8776149f196d1acb24d18099c33c7806a40889
MD5 5c578d532abcbe88b3d1d88752d808b3
BLAKE2b-256 a163f2809a8e4d0333aa3a2dddba5e14ba797e7c4309634d3eeb5429de38b95a

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: figurex-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 35.4 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.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a38a8cd29f079a86c53ea7cbdfb95dcde5cd96d664d863d04279992875c3532f
MD5 f5e388f85e6af81680cefcc52f28fb0e
BLAKE2b-256 7540dda9a7b4123f816d08d0b7de86c15bd163af34e32cf86a0a7dee09354e53

See more details on using hashes here.

Provenance

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