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 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)
- Check out the Examples Notebook!
Documentation
A documentation and API reference can be found on ReadTheDocs:
- Figure (context manager)
- Panel (context manager)
- Basemap (context manager)
- Cartopy (context manager)
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]
If you work with uv, replace pip install by uv add.
Requirements
- python >3.10
- numpy >2.0
- matplotlib >3.0
- basemap >=2.0 (optional)
- cartopy >=0.25 (optional)
- scipy (optional, required by cartopy)
Related
- A discussion on GitHub/matplotlib actually requested this feature long ago.
- The project GitHub/contextplt has implemented a similar concept.
Metadata
Release files for figurex 0.2.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| figurex-0.2.15.tar.gz | 15.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| figurex-0.2.15-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.1 kB
Release files / figurex-0.2.15.tar.gz
| Download URL | figurex-0.2.15.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
842ec96065d390f638e650a3c1e2db11a559817aa9c69e74c4754c736edfee56
|
|
BLAKE2b-256 checksum How to use checksums |
f247269817b100da599eb31d24cf0e9eaca677b683e7f0948ebe7a8cf86354cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.5
|
Release files / figurex-0.2.15-py3-none-any.whl
| Download URL | figurex-0.2.15-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7696f90f01e5d6b75e5df4ffefecf29fa90089b35dea79493b924bec5823a6fa
|
|
BLAKE2b-256 checksum How to use checksums |
14cca7dd1bb86f907ef7194be9657d3e05c8afaefabc2d6fc27aa3cb206a8abd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.5
|
Security for figurex 0.2.15
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.