figurex


Namefigurex JSON
Version 0.2.6 PyPI version JSON
download
home_pagehttps://github.com/mschroen/figurex
SummaryMake figures with context managers in python: quicker, simpler, more readable.
upload_time2024-11-17 19:33:10
maintainerNone
docs_urlNone
authorMartin Schrön
requires_python>3.9
licenseMIT
keywords plot matplotlib cartopy basemap
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Figurex
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)


## 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/ef/26/8cec348fc4715a78bd98e90923c47e70b7eba11166f782c37bbf8a9ac002/figurex-0.2.6.tar.gz",
    "platform": null,
    "description": "# Figurex\nMake figures with context managers in python: quicker, simpler, more readable. \n\n\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## 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.6",
    "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": "676b382d2b7a642052e509124f54e4869d17648405a6e956b08a933d9f9ef18e",
                "md5": "88ffba85b506a512685a4be4603f7995",
                "sha256": "988c9a53802006fd4f8e01c86637bafeaa8959935faeb23139ec2dbb51ae4eaf"
            },
            "downloads": -1,
            "filename": "figurex-0.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "88ffba85b506a512685a4be4603f7995",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">3.9",
            "size": 14800,
            "upload_time": "2024-11-17T19:33:09",
            "upload_time_iso_8601": "2024-11-17T19:33:09.671590Z",
            "url": "https://files.pythonhosted.org/packages/67/6b/382d2b7a642052e509124f54e4869d17648405a6e956b08a933d9f9ef18e/figurex-0.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ef268cec348fc4715a78bd98e90923c47e70b7eba11166f782c37bbf8a9ac002",
                "md5": "056c91a06a772c85582192528b59de1e",
                "sha256": "03d90794820df942eb88f0c37e362909e2b079d3f2ff97267b8b2f05e8bddddf"
            },
            "downloads": -1,
            "filename": "figurex-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "056c91a06a772c85582192528b59de1e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">3.9",
            "size": 12053,
            "upload_time": "2024-11-17T19:33:10",
            "upload_time_iso_8601": "2024-11-17T19:33:10.795060Z",
            "url": "https://files.pythonhosted.org/packages/ef/26/8cec348fc4715a78bd98e90923c47e70b7eba11166f782c37bbf8a9ac002/figurex-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-17 19:33:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mschroen",
    "github_project": "figurex",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "figurex"
}
        
Elapsed time: 3.18300s