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.
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])
It is just a wrapper around standard matplotlib code, 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", zorder=20, color="r", s=200, lw=2)
- Check out the Examples Notebook!
Related projects:
- A discussion on GitHub/matplotlib actually requested this feature long ago.
- The project GitHub/contextplt has implemented a similar concept.
Project details
Release history Release notifications | RSS feed
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.4.tar.gz
(20.9 kB
view details)
Built Distribution
figurex-0.1.4-py3-none-any.whl
(35.1 kB
view details)
File details
Details for the file figurex-0.1.4.tar.gz
.
File metadata
- Download URL: figurex-0.1.4.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.9 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd9cd5a3d53a503e2bae2cb4a0701ba54850e511c6707b4bdc4e5950ad6b3159 |
|
MD5 | f665e47b7a162a577a93336b4617a9e9 |
|
BLAKE2b-256 | cfc4a1a90349da30ea538bce1ffe3988bda4537e0b90bb7e61fece68361f5a4e |
Provenance
File details
Details for the file figurex-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: figurex-0.1.4-py3-none-any.whl
- Upload date:
- Size: 35.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.11.9 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6e48a8c7fcf543f7dcccb5660dc483627d2bc5c24c5beef0dcb6fe571ff7c10 |
|
MD5 | 81f56edaf354351df0fe813ce660d01f |
|
BLAKE2b-256 | a430c1f0549ae6a74385f94a8c8148b9a0f93d317147d9c06b85171e40b7af14 |