# Figurex
[![PyPi Version](https://img.shields.io/pypi/v/figurex.svg)](https://pypi.python.org/pypi/figurex/)
[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/mschroen/figurex/blob/main/LICENSE)
[![Read the Docs](https://readthedocs.org/projects/figurex/badge/?version=latest)](https://figurex.readthedocs.io/en/latest/?badge=latest)
[![Issues](https://img.shields.io/github/issues-raw/mschroen/figurex.svg?maxAge=25000)](https://github.com/mschroen/figurex/issues)
Make figures with context managers in python: quicker, simpler, more readable.
```python
with Figure() as ax:
ax.plot([1,2],[3,4])
```
## Idea
Tired of lengthy matplotlib code just for simple plotting?
```python
# 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:
```python
# 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:
```python
with Figure("A simple plot") as ax:
ax.plot([1,2],[3,4])
```
A plot with two panels:
```python
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):
```python
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:
```python
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](https://github.com/mschroen/figurex/blob/main/examples.ipynb)!
![Figurex examples](https://github.com/mschroen/figurex/blob/main/docs/figurex-examples.png)
## Documentation
A documentation and API reference can be found on [ReadTheDocs](https://figurex.readthedocs.io/en/latest):
- [Figure](https://figurex.readthedocs.io/en/latest/#figurex.figure.Figure) (context manager)
- [Panel](https://figurex.readthedocs.io/en/latest/#figurex.figure.Panel) (context manager)
- [Basemap](https://figurex.readthedocs.io/en/latest/#figurex.basemap.Basemap) (context manager)
- [Cartopy](https://figurex.readthedocs.io/en/latest/#figurex.cartopy.Cartopy) (context manager)
## Install
```bash
pip install figurex
```
If you want to use geospatial mapping features with [Basemap](https://pypi.org/project/basemap/) or [Cartopy](https://pypi.org/project/Cartopy/), install the corresponding optional features:
```bash
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
- A discussion on [GitHub/matplotlib](https://github.com/matplotlib/matplotlib/issues/5218/) actually requested this feature long ago.
- The project [GitHub/contextplt](https://toshiakiasakura.github.io/contextplt/notebooks/usage.html) has implemented a similar concept.
Raw data
{
"_id": null,
"home_page": "https://github.com/mschroen/figurex",
"name": "figurex",
"maintainer": null,
"docs_url": null,
"requires_python": ">3.9",
"maintainer_email": null,
"keywords": "plot, matplotlib, cartopy, basemap",
"author": "Martin Schr\u00f6n",
"author_email": "martin@schroen.eu",
"download_url": "https://files.pythonhosted.org/packages/7d/c3/ed8998a82f7a2fb6d4623ab2789d94958059d93101b74b60885028ddfa4d/figurex-0.2.11.tar.gz",
"platform": null,
"description": "# Figurex\n[![PyPi Version](https://img.shields.io/pypi/v/figurex.svg)](https://pypi.python.org/pypi/figurex/)\n[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/mschroen/figurex/blob/main/LICENSE)\n[![Read the Docs](https://readthedocs.org/projects/figurex/badge/?version=latest)](https://figurex.readthedocs.io/en/latest/?badge=latest)\n[![Issues](https://img.shields.io/github/issues-raw/mschroen/figurex.svg?maxAge=25000)](https://github.com/mschroen/figurex/issues) \nMake figures with context managers in python: quicker, simpler, more readable. \n```python\nwith Figure() as ax:\n ax.plot([1,2],[3,4])\n```\n\n\n## Idea \n\nTired of lengthy matplotlib code just for simple plotting? \n```python\n# How plotting used to be:\nimport matplotlib.pyplot as plt\n\nfig, axes = plt.subplots(1,2, figsize=(4,5))\nplt.set_title(\"My plot\")\nax = axes[0]\nax.plot([1,2],[3,4])\nax = axes[1]\nax.plot([2,3],[4,5])\nfig.savefig(\"file.png\", bbox_inches='tight')\nplt.show()\n```\nBeautify your daily work with shorter and more readable code:\n```python\n# How plotting becomes with figurex:\nfrom figurex import Figure, Panel\n\nwith Figure(\"My plot\", layout=(1,2), size=(4,5), save=\"file.png\"):\n with Panel() as ax:\n ax.plot([1,2],[3,4])\n with Panel() as ax:\n ax.plot([2,3],[4,5])\n```\nThe `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!\n\n## Examples\n\nMake a simple plot:\n\n```python\nwith Figure(\"A simple plot\") as ax:\n ax.plot([1,2],[3,4])\n```\n\nA plot with two panels:\n```python\nwith Figure(layout=(1,2), size=(6,3)):\n with Panel(\"a) Magic\") as ax:\n ax.plot([1,2],[3,4])\n with Panel(\"b) Reality\", grid=\"\") as ax:\n ax.plot([5,5],[6,4])\n```\n\nSave a plot into memory for later use (e.g. in FPDF):\n```python\nwith Figure(\"Tea party\", show=False):\n with Panel() as ax:\n ax.plot([5,5],[6,4])\nmy_figure = Figure.as_object()\n# <_io.BytesIO at 0x...>\n```\n\nPlotting maps:\n```python\nfrom figurex.basemap import Basemap\n\nwith Figure(size=(3,3)):\n with Basemap(\"Germany\", extent=(5,15,46,55), tiles=\"relief\") as Map:\n x,y = Map(12.385, 51.331)\n Map.scatter(x, y, marker=\"x\", color=\"red\", s=200)\n``` \n \n- Check out the [Examples Notebook](https://github.com/mschroen/figurex/blob/main/examples.ipynb)!\n\n![Figurex examples](https://github.com/mschroen/figurex/blob/main/docs/figurex-examples.png)\n\n\n## Documentation\n\nA documentation and API reference can be found on [ReadTheDocs](https://figurex.readthedocs.io/en/latest):\n- [Figure](https://figurex.readthedocs.io/en/latest/#figurex.figure.Figure) (context manager)\n- [Panel](https://figurex.readthedocs.io/en/latest/#figurex.figure.Panel) (context manager)\n- [Basemap](https://figurex.readthedocs.io/en/latest/#figurex.basemap.Basemap) (context manager)\n- [Cartopy](https://figurex.readthedocs.io/en/latest/#figurex.cartopy.Cartopy) (context manager)\n\n## Install\n\n```bash\npip install figurex\n```\n\nIf you want to use geospatial mapping features with [Basemap](https://pypi.org/project/basemap/) or [Cartopy](https://pypi.org/project/Cartopy/), install the corresponding optional features:\n```bash\npip install figurex[basemap]\npip install figurex[cartopy]\n```\n\n### Requirements\n\n- python >3.9\n- numpy\n- matplotlib\n- basemap >=1.4.1 (optional)\n- cartopy >=0.23 (optional)\n- scipy (optional, required by cartopy)\n\n## Related\n\n- A discussion on [GitHub/matplotlib](https://github.com/matplotlib/matplotlib/issues/5218/) actually requested this feature long ago.\n- The project [GitHub/contextplt](https://toshiakiasakura.github.io/contextplt/notebooks/usage.html) has implemented a similar concept.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Make figures with context managers in python: quicker, simpler, more readable.",
"version": "0.2.11",
"project_urls": {
"Homepage": "https://github.com/mschroen/figurex",
"Repository": "https://github.com/mschroen/figurex"
},
"split_keywords": [
"plot",
" matplotlib",
" cartopy",
" basemap"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "84597bc67e1cd1ca4ca03613fd713a33d809a43c6fc6fe20321521ed0f63fca0",
"md5": "83dec0b50167954ce3f52e335ea6737e",
"sha256": "34472373ec913a76f37d9964558d5075478362bebdbdb18246b4bde83a19027f"
},
"downloads": -1,
"filename": "figurex-0.2.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "83dec0b50167954ce3f52e335ea6737e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">3.9",
"size": 15190,
"upload_time": "2025-01-08T16:28:03",
"upload_time_iso_8601": "2025-01-08T16:28:03.825857Z",
"url": "https://files.pythonhosted.org/packages/84/59/7bc67e1cd1ca4ca03613fd713a33d809a43c6fc6fe20321521ed0f63fca0/figurex-0.2.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7dc3ed8998a82f7a2fb6d4623ab2789d94958059d93101b74b60885028ddfa4d",
"md5": "4bcb066c432dbd35fcca03d8ff29b1fa",
"sha256": "b1687c74229c901fed93f3e6f9cd4d8988bc0596abfa6268ee58faa4109546d4"
},
"downloads": -1,
"filename": "figurex-0.2.11.tar.gz",
"has_sig": false,
"md5_digest": "4bcb066c432dbd35fcca03d8ff29b1fa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">3.9",
"size": 12416,
"upload_time": "2025-01-08T16:28:05",
"upload_time_iso_8601": "2025-01-08T16:28:05.889619Z",
"url": "https://files.pythonhosted.org/packages/7d/c3/ed8998a82f7a2fb6d4623ab2789d94958059d93101b74b60885028ddfa4d/figurex-0.2.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-08 16:28:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mschroen",
"github_project": "figurex",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "figurex"
}