Name | smartplot JSON |
Version |
0.1.2
JSON |
| download |
home_page | |
Summary | A helper tool for matplotlib. Provides a contextmanager which automatically saves data used to make plots and automatically generates a script to re-load and re-plot this data at a later stage. |
upload_time | 2023-07-20 13:02:34 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.0 |
license | BSD-3-Clause |
keywords |
save data
matplotlib
plt
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Smartplot
This package provides a simple contextmanager which automatically saves data used to make matplotlib plots and automatically generates a script to reproduce the plot at a later stage.
## Install
`pip install smartplot`
## Basic Usage
A SmartPlotContext contextmanager can be used in conjunction with a *with* block as shown below.
```python
from smartplot import SmartPlotContext
with SmartPlotContext("./data-save-dir", locals(), overwrite=True) as spl:
spl.plot( ... )
...
spl.title( ... )
spl.show()
```
The resulting context manager `spl` support all matplotlib.pyplot function calls.
All calls made to `spl` are passed onto matplotlib.pyplot as-is and recorded.
The data save directory is dynamically created if it does not exist and is populated with pickle files containing the data used to make the plot.
The automatically generated `make_plot.py` script contains code which reloads all data and contains the necessary calls to matplotlib.pyplot used to create the original plot.
This script may then be modified to adjust the plot.
If the data save directory is not empty an exception is raised unless `overwrite=True`.
Passing in `locals()` allows SmartPlotContext to infer the original variable names for the objects used for re-use in `make_plot.py`.
Note that only calls directly to spl are recorded, if you use figures and axes directly, you're on your own for now.
## Example Usage
```python
import numpy as np
import matplotlib.pyplot as plt
from smartplot import SmartPlotContext
x_data = np.linspace(0, 2 * np.pi, 1000)
y_data = np.sin(x_data)
with SmartPlotContext("./data-save-dir", locals(), overwrite=True) as spl:
spl.plot(x_data, y_data, c='k', label='sin')
spl.plot(x_data, np.cos(x_data), c='b', label='cos')
spl.xlabel('xaxis')
spl.ylabel('yaxis')
spl.title('Title')
spl.legend()
spl.savefig('plot.pdf')
spl.show()
```
This will generate the following directory structure
```
data-save-dir/
make_plot.py
unnamed_arg.pkl
x_data.pkl
y_data.pkl
```
The contents of `make_plot.py` would be
```python
import numpy as np
import matplotlib.pyplot as plt
from smartplot import load_pickle
x_data = load_pickle('x_data.pkl')
y_data = load_pickle('y_data.pkl')
unnamed_arg = load_pickle('unnamed_arg.pkl')
plt.plot(x_data, y_data, c='k', label='sin')
plt.plot(x_data, unnamed_arg, c='b', label='cos')
plt.xlabel('xaxis')
plt.ylabel('yaxis')
plt.title('Title')
plt.legend()
plt.savefig('plot.pdf')
plt.show()
```
which should perfectly reproduce the original plot.
Note that the variable names `x_data` and `y_data` are arbitrary and were inferred by the SmartPlotContext using the locals() dict.
Good code structure will always allow SmartPlotContext to infer the correct variable names.
Anonymous arguments, such as the y data of the `np.cos` plot are simply saved and named "unnamed_arg" with an integer postfix if multiple unnamed arguments are present.
## Misc
Please report any bugs or feature requests to `jero.wilkinson@gmail.com`.
Raw data
{
"_id": null,
"home_page": "",
"name": "smartplot",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.0",
"maintainer_email": "",
"keywords": "save data,matplotlib,plt",
"author": "",
"author_email": "Jeremy John Henry Wilkinson <jero.wilkinson@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/01/d4/856395b3cbddd1f7229d46691129ad1cb4aa9b0fa6a1c225d5bc2fd3f1c8/smartplot-0.1.2.tar.gz",
"platform": null,
"description": "# Smartplot\n\nThis package provides a simple contextmanager which automatically saves data used to make matplotlib plots and automatically generates a script to reproduce the plot at a later stage.\n\n## Install\n\n`pip install smartplot`\n\n## Basic Usage\n\nA SmartPlotContext contextmanager can be used in conjunction with a *with* block as shown below. \n\n```python\nfrom smartplot import SmartPlotContext\n\n\nwith SmartPlotContext(\"./data-save-dir\", locals(), overwrite=True) as spl:\n spl.plot( ... )\n ...\n spl.title( ... )\n spl.show()\n```\n\nThe resulting context manager `spl` support all matplotlib.pyplot function calls.\nAll calls made to `spl` are passed onto matplotlib.pyplot as-is and recorded.\nThe data save directory is dynamically created if it does not exist and is populated with pickle files containing the data used to make the plot.\nThe automatically generated `make_plot.py` script contains code which reloads all data and contains the necessary calls to matplotlib.pyplot used to create the original plot.\nThis script may then be modified to adjust the plot.\nIf the data save directory is not empty an exception is raised unless `overwrite=True`.\nPassing in `locals()` allows SmartPlotContext to infer the original variable names for the objects used for re-use in `make_plot.py`.\n\nNote that only calls directly to spl are recorded, if you use figures and axes directly, you're on your own for now.\n\n## Example Usage\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom smartplot import SmartPlotContext\n\n\nx_data = np.linspace(0, 2 * np.pi, 1000)\ny_data = np.sin(x_data)\nwith SmartPlotContext(\"./data-save-dir\", locals(), overwrite=True) as spl:\n spl.plot(x_data, y_data, c='k', label='sin')\n spl.plot(x_data, np.cos(x_data), c='b', label='cos')\n spl.xlabel('xaxis')\n spl.ylabel('yaxis')\n spl.title('Title')\n spl.legend()\n spl.savefig('plot.pdf')\n spl.show()\n```\n\nThis will generate the following directory structure\n\n```\ndata-save-dir/\n make_plot.py\n unnamed_arg.pkl\n x_data.pkl\n y_data.pkl\n```\n\nThe contents of `make_plot.py` would be\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom smartplot import load_pickle\n\n\nx_data = load_pickle('x_data.pkl')\ny_data = load_pickle('y_data.pkl')\nunnamed_arg = load_pickle('unnamed_arg.pkl')\n\nplt.plot(x_data, y_data, c='k', label='sin')\nplt.plot(x_data, unnamed_arg, c='b', label='cos')\nplt.xlabel('xaxis')\nplt.ylabel('yaxis')\nplt.title('Title')\nplt.legend()\nplt.savefig('plot.pdf')\nplt.show()\n```\n\nwhich should perfectly reproduce the original plot.\nNote that the variable names `x_data` and `y_data` are arbitrary and were inferred by the SmartPlotContext using the locals() dict.\nGood code structure will always allow SmartPlotContext to infer the correct variable names.\nAnonymous arguments, such as the y data of the `np.cos` plot are simply saved and named \"unnamed_arg\" with an integer postfix if multiple unnamed arguments are present.\n\n## Misc\n\nPlease report any bugs or feature requests to `jero.wilkinson@gmail.com`.\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "A helper tool for matplotlib. Provides a contextmanager which automatically saves data used to make plots and automatically generates a script to re-load and re-plot this data at a later stage.",
"version": "0.1.2",
"project_urls": null,
"split_keywords": [
"save data",
"matplotlib",
"plt"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7a26c88f9c38886f6571ed4813da9a1907116635b27eed626fcea2c62236a49c",
"md5": "edc879a8876fd5b828b1004e5347b82b",
"sha256": "6ed21bd1c709fd3fc325802b681e2cc95df9e026d725b10de4944819be9c47b3"
},
"downloads": -1,
"filename": "smartplot-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "edc879a8876fd5b828b1004e5347b82b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.0",
"size": 4559,
"upload_time": "2023-07-20T13:02:33",
"upload_time_iso_8601": "2023-07-20T13:02:33.067413Z",
"url": "https://files.pythonhosted.org/packages/7a/26/c88f9c38886f6571ed4813da9a1907116635b27eed626fcea2c62236a49c/smartplot-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "01d4856395b3cbddd1f7229d46691129ad1cb4aa9b0fa6a1c225d5bc2fd3f1c8",
"md5": "84730e729fedc5cd81ead671b8cee8c7",
"sha256": "f23a6742babd496becf8283b5ebf4d9bd1218372857765f35fefff2e31934b73"
},
"downloads": -1,
"filename": "smartplot-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "84730e729fedc5cd81ead671b8cee8c7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.0",
"size": 4394,
"upload_time": "2023-07-20T13:02:34",
"upload_time_iso_8601": "2023-07-20T13:02:34.536733Z",
"url": "https://files.pythonhosted.org/packages/01/d4/856395b3cbddd1f7229d46691129ad1cb4aa9b0fa6a1c225d5bc2fd3f1c8/smartplot-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-20 13:02:34",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "smartplot"
}