Name | figurestream JSON |
Version |
1.2.8
JSON |
| download |
home_page | |
Summary | A Matplotlib.Figure fork with real-time plot streaming features. |
upload_time | 2023-08-08 17:23:53 |
maintainer | Yeison Cardona |
docs_url | None |
author | Yeison Cardona |
requires_python | >=3.8 |
license | BSD-2-Clause |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Matplotlib-FigureStream
A backend for serve Matplotlib animations as web streams.







[](https://figurestream.readthedocs.io/en/latest/?badge=latest)
## Instalation
```python
pip install figurestream
```
## Bare minimum
By default, the stream serves on http://localhost:5000
```python
# FigureStream replace any Figure object
from figurestream import FigureStream
import numpy as np
from datetime import datetime
# FigureStream can be used like any Figure object
stream = FigureStream()
sub = stream.add_subplot(111)
x = np.linspace(0, 3, 1000)
# Update animation loop
while True:
sub.clear() # clear the canvas
# ------------------------------------------------------------------------
# Any plot operation
sub.set_title('FigureStream')
sub.set_xlabel('Time [s]')
sub.set_ylabel('Amplitude')
sub.plot(x, np.sin(2 * np.pi * 2 * (x + datetime.now().timestamp())))
sub.plot(x, np.sin(2 * np.pi * 0.5 * (x + datetime.now().timestamp())))
# ------------------------------------------------------------------------
stream.feed() # push the frame into the server
```
For fast updates is recommended to use `set_data`, `set_ydata` and `set_xdata` instead of clear and draw again in each loop, also `FigureStream` can be implemented from a custom class.
```python
# FigureStream replace any Figure object
from figurestream import FigureStream
import numpy as np
from datetime import datetime
class FastAnimation(FigureStream):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
axis = self.add_subplot(111)
self.x = np.linspace(0, 3, 1000)
# ------------------------------------------------------------------------
# Single time plot configuration
axis.set_title('FigureStream')
axis.set_xlabel('Time [s]')
axis.set_ylabel('Amplitude')
axis.set_ylim(-1.2, 1.2)
axis.set_xlim(0, 3)
# Lines objects
self.line1, *_ = axis.plot(self.x, np.zeros(self.x.size))
self.line2, *_ = axis.plot(self.x, np.zeros(self.x.size))
# ------------------------------------------------------------------------
self.anim()
def anim(self):
# Update animation loop
while True:
# ------------------------------------------------------------------------
# Update only the data values is faster than update all the plot
self.line1.set_ydata(np.sin(2 * np.pi * 2 * (self.x + datetime.now().timestamp())))
self.line2.set_ydata(np.sin(2 * np.pi * 0.5 * (self.x + datetime.now().timestamp())))
# ------------------------------------------------------------------------
self.feed() # push the frame into the server
if __name__ == '__main__':
FastAnimation()
```
## Set host, port and endpoint
If we want to serve the stream in a different place we can use the parameters `host`, `port` and `endpoint`, for example:
```python
FigureStream(host='0.0.0.0', port='5500', endpoint='figure.jpeg')
```
Now the stream will serve on http://localhost:5500/figure.jpeg and due the `0.0.0.0` host is accesible for any device on network.
By default `host` is `localhost`, `port` is `5000` and endopoint is empty.
Raw data
{
"_id": null,
"home_page": "",
"name": "figurestream",
"maintainer": "Yeison Cardona",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "yencardonaal@unal.edu.co",
"keywords": "",
"author": "Yeison Cardona",
"author_email": "yencardonaal@unal.edu.co",
"download_url": "https://files.pythonhosted.org/packages/0b/a3/8f901392d9d918f05765e87986fea56353d53e08b2c1d5a1c92cc98e811f/figurestream-1.2.8.tar.gz",
"platform": null,
"description": "# Matplotlib-FigureStream\n\nA backend for serve Matplotlib animations as web streams.\n\n\n\n\n\n\n\n\n[](https://figurestream.readthedocs.io/en/latest/?badge=latest)\n\n## Instalation\n\n\n```python\npip install figurestream\n```\n\n## Bare minimum\n\nBy default, the stream serves on http://localhost:5000\n\n\n```python\n# FigureStream replace any Figure object \nfrom figurestream import FigureStream\n\nimport numpy as np\nfrom datetime import datetime\n\n# FigureStream can be used like any Figure object\nstream = FigureStream()\nsub = stream.add_subplot(111)\nx = np.linspace(0, 3, 1000)\n\n# Update animation loop\nwhile True:\n sub.clear() # clear the canvas\n\n # ------------------------------------------------------------------------\n # Any plot operation \n sub.set_title('FigureStream')\n sub.set_xlabel('Time [s]')\n sub.set_ylabel('Amplitude')\n sub.plot(x, np.sin(2 * np.pi * 2 * (x + datetime.now().timestamp())))\n sub.plot(x, np.sin(2 * np.pi * 0.5 * (x + datetime.now().timestamp())))\n # ------------------------------------------------------------------------\n \n stream.feed() # push the frame into the server\n```\n\nFor fast updates is recommended to use `set_data`, `set_ydata` and `set_xdata` instead of clear and draw again in each loop, also `FigureStream` can be implemented from a custom class.\n\n\n```python\n# FigureStream replace any Figure object\nfrom figurestream import FigureStream\n\nimport numpy as np\nfrom datetime import datetime\n\n\nclass FastAnimation(FigureStream):\n\n def __init__(self, *args, **kwargs):\n super().__init__(*args, **kwargs)\n\n axis = self.add_subplot(111)\n self.x = np.linspace(0, 3, 1000)\n \n # ------------------------------------------------------------------------\n # Single time plot configuration\n axis.set_title('FigureStream')\n axis.set_xlabel('Time [s]')\n axis.set_ylabel('Amplitude')\n\n axis.set_ylim(-1.2, 1.2)\n axis.set_xlim(0, 3)\n \n # Lines objects\n self.line1, *_ = axis.plot(self.x, np.zeros(self.x.size))\n self.line2, *_ = axis.plot(self.x, np.zeros(self.x.size))\n # ------------------------------------------------------------------------\n\n self.anim()\n\n def anim(self):\n # Update animation loop\n while True:\n # ------------------------------------------------------------------------\n # Update only the data values is faster than update all the plot\n self.line1.set_ydata(np.sin(2 * np.pi * 2 * (self.x + datetime.now().timestamp())))\n self.line2.set_ydata(np.sin(2 * np.pi * 0.5 * (self.x + datetime.now().timestamp())))\n # ------------------------------------------------------------------------\n \n self.feed() # push the frame into the server\n\n\nif __name__ == '__main__':\n FastAnimation()\n```\n\n## Set host, port and endpoint\n\nIf we want to serve the stream in a different place we can use the parameters `host`, `port` and `endpoint`, for example:\n\n\n```python\nFigureStream(host='0.0.0.0', port='5500', endpoint='figure.jpeg')\n```\n\nNow the stream will serve on http://localhost:5500/figure.jpeg and due the `0.0.0.0` host is accesible for any device on network. \nBy default `host` is `localhost`, `port` is `5000` and endopoint is empty.\n",
"bugtrack_url": null,
"license": "BSD-2-Clause",
"summary": "A Matplotlib.Figure fork with real-time plot streaming features.",
"version": "1.2.8",
"project_urls": {
"Download": "https://github.com/UN-GCPDS/matplotlib-figurestream"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fb9ab342fed54825615302518aa2ac1865a2a7bba59cc864b3cd63a385680165",
"md5": "43a9c3f74a24763cb22ed3bb5e47d68e",
"sha256": "eb31838039aec45feb5c7919908092baad1a0b92034d2f8eb54b3653a3dfcf68"
},
"downloads": -1,
"filename": "figurestream-1.2.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "43a9c3f74a24763cb22ed3bb5e47d68e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 6244,
"upload_time": "2023-08-08T17:23:52",
"upload_time_iso_8601": "2023-08-08T17:23:52.499568Z",
"url": "https://files.pythonhosted.org/packages/fb/9a/b342fed54825615302518aa2ac1865a2a7bba59cc864b3cd63a385680165/figurestream-1.2.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0ba38f901392d9d918f05765e87986fea56353d53e08b2c1d5a1c92cc98e811f",
"md5": "3a210a4bb67752a98a746abd6fcc3cc6",
"sha256": "c9c358b7d1954cc9da4ac073ebec520f93bce9e3ff7e0b418d2fb50ada562c31"
},
"downloads": -1,
"filename": "figurestream-1.2.8.tar.gz",
"has_sig": false,
"md5_digest": "3a210a4bb67752a98a746abd6fcc3cc6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6355,
"upload_time": "2023-08-08T17:23:53",
"upload_time_iso_8601": "2023-08-08T17:23:53.623712Z",
"url": "https://files.pythonhosted.org/packages/0b/a3/8f901392d9d918f05765e87986fea56353d53e08b2c1d5a1c92cc98e811f/figurestream-1.2.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-08 17:23:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "UN-GCPDS",
"github_project": "matplotlib-figurestream",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "figurestream"
}