figurex


Namefigurex JSON
Version 0.2.7 PyPI version JSON
download
home_pagehttps://github.com/mschroen/figurex
SummaryMake figures with context managers in python: quicker, simpler, more readable.
upload_time2024-11-18 02:34:22
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/1a/bd/e6933febd0d565630404539e94918baae8300562e4503ac87d3ef35043b0/figurex-0.2.7.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.7",
    "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": "e62e864e3ff984666a58392ab81409af0f7f7f1bdfecdf26f9ce30c506128ebb",
                "md5": "3501f2491bd43dd4335af7d73d9d2f13",
                "sha256": "4a4b5f5cc14ed2785f24c834caa92cc94b07494a1178d0b8dd31f23da67d9b6d"
            },
            "downloads": -1,
            "filename": "figurex-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3501f2491bd43dd4335af7d73d9d2f13",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">3.9",
            "size": 14815,
            "upload_time": "2024-11-18T02:34:21",
            "upload_time_iso_8601": "2024-11-18T02:34:21.541092Z",
            "url": "https://files.pythonhosted.org/packages/e6/2e/864e3ff984666a58392ab81409af0f7f7f1bdfecdf26f9ce30c506128ebb/figurex-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1abde6933febd0d565630404539e94918baae8300562e4503ac87d3ef35043b0",
                "md5": "4bd9ba20ae6f7fc8ac29d165408b3921",
                "sha256": "252fd965eaa89e2e5bd065df7b86e7d4e70de835c29b21fb1b13dcbd3409dbd5"
            },
            "downloads": -1,
            "filename": "figurex-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "4bd9ba20ae6f7fc8ac29d165408b3921",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">3.9",
            "size": 12017,
            "upload_time": "2024-11-18T02:34:22",
            "upload_time_iso_8601": "2024-11-18T02:34:22.908514Z",
            "url": "https://files.pythonhosted.org/packages/1a/bd/e6933febd0d565630404539e94918baae8300562e4503ac87d3ef35043b0/figurex-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-18 02:34:22",
    "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: 0.35163s