# animplotlib
This package acts as a thin wrapper around the
`matplotlib.animation.FuncAnimation` class to simplify animating `matplotlib`
plots.

## Installation
```
pip install animplotlib
```
## User manual
There are two classes which can be called: `AnimPlot`, for 2-D plots,
and `AnimPlot3D`, for 3-D plots.
### AnimPlot
As an example, below is a demonstration of the steps required to make a
basic plot of an Euler spiral. An Euler spiral can be obtained by plotting
the [Fresnel integrals](https://en.wikipedia.org/wiki/Fresnel_integral),
which can be generated using `scipy.special`.
Import the necessary libraries and create a `matplotlib` figure and axes:
```python
import animplotlib as anim
import numpy as np
import matplotlib.pyplot as plt
import scipy.special as sc
fig = plt.figure()
ax = fig.add_subplot(111)
```
Generate the points being plotted:
```python
x = np.linspace(-10, 10, 2500)
y, z = sc.fresnel(x)
```
Create two empty `matplotlib` plots: one to plot the points up to the current
most point (i.e. the 'line') and one to plot the current most point:
```python
line, = ax.plot([], [], lw=1)
point, = ax.plot([], [], 'o')
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
```
Call the `AnimPlot` class and show the plot:
```python
animation = anim.AnimPlot(fig, line, point, y, z, l_num=len(x),
plot_speed=5)
plt.show()
```
`l_num` is the number of points before the current most point being plotted to
`line`. The default value is set to 10, however in this example it makes sense
to set it to the same length as `x` (i.e. all the points before the current most
point are plotted). Similarly, an argument `p_num` can be passed to determine
the number of points being plotted to `point`. This is set to 1 by default.
Optional arguments:
* `plot_speed` (`int`) : set to 10 by default.
* `l_num` (`int`) : The number of points being plotted to `line` each frame. By
default this is set to 10.
* `p_num` (`int`) : The number of points being plotted to `point` each frame. By
default, this is set to 1, i.e. only the current most point is plotted each
frame (the orange point in the gif).
* `save_as` (`str`) : file name to save the animation as a gif in the
current working directory.
* `**kwargs` : other arguments passable into
`matplotlib.animation.FuncAnimation` (see [the docs](https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.animation.FuncAnimation.html) for more info).
<!--  -->
<center>
<figure>
<img src="https://raw.githubusercontent.com/aymenhafeez/animplotlib/master/examples/gifs/fresnel_2d.gif" height='331' width='450' />
</figure>
</center>
### AnimPlot3D
Creating a 3-D animated plot is similar to creating a 2-D plot but with a
few additional steps.
```python
import animplotlib as anim
import numpy as np
import matplotlib.pyplot as plt
import scipy.special as sc
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.linspace(-10, 10, 3000)
y, z = sc.fresnel(x)
```
For 3-D plots, two empty `matplotlib` plots must be created:
```python
lines, = [ax.plot([], [], [])]
points, = [ax.plot([], [], [], 'o')]
```
The second plot, `points`, by default plots the 'ith' point each frame. After
that set the x, y and z limits and call the `AnimPlot3D` class.
```python
ax.set_xlim(-10, 10)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)
animation = anim.AnimPlot3D(fig, ax, [lines], [points], x, y, z, plot_speed=5)
plt.show()
```
<!--  -->
<center>
<figure>
<img src="https://raw.githubusercontent.com/aymenhafeez/animplotlib/master/examples/gifs/fresnel_3d.gif" height='402' width='450' />
</figure>
</center>
Optional arguments:
* `plot_speed` (`int`) : set to 10 by default.
* `rotation_speed` (`int`) : proportional to `plot_speed`. Off by default,
enabled by setting a value.
* `l_num` (`int`) : The number of points being plotted to `lines` each frame. By
default, all the points up until the current point get plotted.
* `p_num` (`int`) : The number of points being plotted to `points` each frame. By
default, this is set to 1, i.e. only the current most point is plotted each
frame (the orange point in the gif).
* `save_as` (`str`) : file name to save the animation as a gif in the
current working directory.
* `**kwargs` : other arguments passable into
`matplotlib.animation.FuncAnimation` (see [the
docs](https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.animation.FuncAnimation.html)
for more info).
Both the 2-D and 3-D plots can be customised visually the same way you would
a normal `matplotlib` plot.
Raw data
{
"_id": null,
"home_page": "https://github.com/aymenhafeez/animplotlib/",
"name": "animplotlib",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Aymen Hafeez",
"author_email": "aymennh@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/eb/75/c6d5d3df815e22107d76aa34a66233fe44f3285cec4fe7b8975a3f669c7f/animplotlib-0.2.4.tar.gz",
"platform": null,
"description": "# animplotlib\n\nThis package acts as a thin wrapper around the\n`matplotlib.animation.FuncAnimation` class to simplify animating `matplotlib`\nplots.\n\n\n\n## Installation\n\n```\npip install animplotlib\n```\n\n\n## User manual \n\nThere are two classes which can be called: `AnimPlot`, for 2-D plots,\nand `AnimPlot3D`, for 3-D plots.\n\n### AnimPlot\n\nAs an example, below is a demonstration of the steps required to make a\nbasic plot of an Euler spiral. An Euler spiral can be obtained by plotting\nthe [Fresnel integrals](https://en.wikipedia.org/wiki/Fresnel_integral),\nwhich can be generated using `scipy.special`.\n\nImport the necessary libraries and create a `matplotlib` figure and axes:\n\n```python\nimport animplotlib as anim\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport scipy.special as sc\n\nfig = plt.figure()\nax = fig.add_subplot(111)\n```\n\nGenerate the points being plotted:\n\n```python\nx = np.linspace(-10, 10, 2500)\ny, z = sc.fresnel(x)\n```\n\nCreate two empty `matplotlib` plots: one to plot the points up to the current\nmost point (i.e. the 'line') and one to plot the current most point:\n\n```python\nline, = ax.plot([], [], lw=1)\npoint, = ax.plot([], [], 'o')\n\nax.set_xlim(-1, 1)\nax.set_ylim(-1, 1)\n```\n \nCall the `AnimPlot` class and show the plot:\n\n```python\nanimation = anim.AnimPlot(fig, line, point, y, z, l_num=len(x),\n plot_speed=5)\nplt.show()\n```\n\n`l_num` is the number of points before the current most point being plotted to\n`line`. The default value is set to 10, however in this example it makes sense\nto set it to the same length as `x` (i.e. all the points before the current most\npoint are plotted). Similarly, an argument `p_num` can be passed to determine\nthe number of points being plotted to `point`. This is set to 1 by default.\n\nOptional arguments:\n* `plot_speed` (`int`) : set to 10 by default.\n* `l_num` (`int`) : The number of points being plotted to `line` each frame. By\ndefault this is set to 10.\n* `p_num` (`int`) : The number of points being plotted to `point` each frame. By\ndefault, this is set to 1, i.e. only the current most point is plotted each\nframe (the orange point in the gif).\n* `save_as` (`str`) : file name to save the animation as a gif in the\n current working directory.\n* `**kwargs` : other arguments passable into\n`matplotlib.animation.FuncAnimation` (see [the docs](https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.animation.FuncAnimation.html) for more info).\n\n<!--  -->\n\n<center>\n <figure> \n <img src=\"https://raw.githubusercontent.com/aymenhafeez/animplotlib/master/examples/gifs/fresnel_2d.gif\" height='331' width='450' /> \n </figure>\n</center>\n\n### AnimPlot3D\n\nCreating a 3-D animated plot is similar to creating a 2-D plot but with a\nfew additional steps.\n\n```python\nimport animplotlib as anim\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport scipy.special as sc\n\nfig = plt.figure()\nax = fig.add_subplot(111, projection='3d')\n\nx = np.linspace(-10, 10, 3000)\ny, z = sc.fresnel(x)\n```\n\nFor 3-D plots, two empty `matplotlib` plots must be created:\n\n```python\nlines, = [ax.plot([], [], [])]\npoints, = [ax.plot([], [], [], 'o')]\n```\n\nThe second plot, `points`, by default plots the 'ith' point each frame. After\nthat set the x, y and z limits and call the `AnimPlot3D` class.\n\n```python\nax.set_xlim(-10, 10)\nax.set_ylim(-1, 1)\nax.set_zlim(-1, 1)\n\nanimation = anim.AnimPlot3D(fig, ax, [lines], [points], x, y, z, plot_speed=5)\nplt.show()\n```\n\n<!--  -->\n\n<center>\n <figure> \n <img src=\"https://raw.githubusercontent.com/aymenhafeez/animplotlib/master/examples/gifs/fresnel_3d.gif\" height='402' width='450' /> \n </figure>\n</center>\n\nOptional arguments:\n* `plot_speed` (`int`) : set to 10 by default.\n* `rotation_speed` (`int`) : proportional to `plot_speed`. Off by default,\nenabled by setting a value.\n* `l_num` (`int`) : The number of points being plotted to `lines` each frame. By\ndefault, all the points up until the current point get plotted.\n* `p_num` (`int`) : The number of points being plotted to `points` each frame. By\ndefault, this is set to 1, i.e. only the current most point is plotted each\nframe (the orange point in the gif).\n* `save_as` (`str`) : file name to save the animation as a gif in the\n current working directory.\n* `**kwargs` : other arguments passable into\n`matplotlib.animation.FuncAnimation` (see [the\ndocs](https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.animation.FuncAnimation.html)\nfor more info).\n\nBoth the 2-D and 3-D plots can be customised visually the same way you would\na normal `matplotlib` plot.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A thin wrapper around the matplotlib FuncAnimation class",
"version": "0.2.4",
"project_urls": {
"Homepage": "https://github.com/aymenhafeez/animplotlib/"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4cdf6878f9d549bbe555c0bfe01f93c2a303decea5f6221354e88ac3a9bf8af6",
"md5": "80e8f52fc3e4c409d1af1b7ed5032d44",
"sha256": "2201b58a51d8cf88b05513ba037be6cf4df34ab4e5146d27f720cc28fe287de3"
},
"downloads": -1,
"filename": "animplotlib-0.2.4-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "80e8f52fc3e4c409d1af1b7ed5032d44",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.7",
"size": 5108,
"upload_time": "2023-10-31T22:47:15",
"upload_time_iso_8601": "2023-10-31T22:47:15.854429Z",
"url": "https://files.pythonhosted.org/packages/4c/df/6878f9d549bbe555c0bfe01f93c2a303decea5f6221354e88ac3a9bf8af6/animplotlib-0.2.4-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "eb75c6d5d3df815e22107d76aa34a66233fe44f3285cec4fe7b8975a3f669c7f",
"md5": "0c0880131ab67c135c3a0fa4a9503b16",
"sha256": "ef414d8bc98ea23cea7988ad3e3f3a8cb2fbfe2c98abbf3737765101705e0c52"
},
"downloads": -1,
"filename": "animplotlib-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "0c0880131ab67c135c3a0fa4a9503b16",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 4689,
"upload_time": "2023-10-31T22:47:18",
"upload_time_iso_8601": "2023-10-31T22:47:18.509470Z",
"url": "https://files.pythonhosted.org/packages/eb/75/c6d5d3df815e22107d76aa34a66233fe44f3285cec4fe7b8975a3f669c7f/animplotlib-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-31 22:47:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aymenhafeez",
"github_project": "animplotlib",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "animplotlib"
}