deephaven-plugin-matplotlib


Namedeephaven-plugin-matplotlib JSON
Version 0.4.1 PyPI version JSON
download
home_pagehttps://github.com/deephaven/deephaven-plugins
SummaryDeephaven Plugin for matplotlib
upload_time2024-05-16 17:43:04
maintainerNone
docs_urlNone
authorDevin Smith
requires_pythonNone
licenseNone
keywords deephaven plugin matplotlib
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Deephaven Plugin for Matplotlib

The Deephaven Plugin for Matplotlib. Allows for opening Matplotlib plots in a Deephaven environment. Any Matplotlib plot
should be viewable by default. For example:

```python
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.subplots()  # Create a figure containing a single axes.
ax.plot([1, 2, 3, 4], [4, 2, 6, 7])  # Plot some data on the axes.
```

You can also use `TableAnimation`, which allows updating a plot whenever a Deephaven Table is updated.

## `TableAnimation` Usage

`TableAnimation` is a Matplotlib `Animation` that is driven by updates in a Deephaven Table. Every time the table that
is being listened to updates, the provided function will run again.

### Line Plot

```python
import matplotlib.pyplot as plt
from deephaven import time_table
from deephaven.plugin.matplotlib import TableAnimation

# Create a ticking table with the sin function
tt = time_table("PT00:00:01").update(["x=i", "y=Math.sin(x)"])

fig = plt.figure()  # Create a new figure
ax = fig.subplots()  # Add an axes to the figure
(line,) = ax.plot(
    [], []
)  # Plot a line. Start with empty data, will get updated with table updates.

# Define our update function. We only look at `data` here as the data is already stored in the format we want
def update_fig(data, update):
    line.set_data([data["x"], data["y"]])

    # Resize and scale the axes. Our data may have expanded and we don't want it to appear off screen.
    ax.relim()
    ax.autoscale_view(True, True, True)


# Create our animation. It will listen for updates on `tt` and call `update_fig` whenever there is an update
ani = TableAnimation(fig, tt, update_fig)
```

### Scatter Plot

Scatter plots require data in a different format that Line plots, so need to pass in the data differently.

```python
import matplotlib.pyplot as plt
from deephaven import time_table
from deephaven.plugin.matplotlib import TableAnimation

tt = time_table("PT00:00:01").update(
    ["x=Math.random()", "y=Math.random()", "z=Math.random()*50"]
)

fig = plt.figure()
ax = fig.subplots()
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
scat = ax.scatter([], [])  # Provide empty data initially
scatter_offsets = []  # Store separate arrays for offsets and sizes
scatter_sizes = []


def update_fig(data, update):
    # This assumes that table is always increasing. Otherwise need to look at other
    # properties in update for creates and removed items
    added = update.added()
    for i in range(0, len(added["x"])):
        # Append new data to the sources
        scatter_offsets.append([added["x"][i], added["y"][i]])
        scatter_sizes.append(added["z"][i])

    # Update the figure
    scat.set_offsets(scatter_offsets)
    scat.set_sizes(scatter_sizes)


ani = TableAnimation(fig, tt, update_fig)
```

### Multiple Series

It's possible to have multiple kinds of series in the same figure. Here is an example driving a line and a scatter plot:

```python
import matplotlib.pyplot as plt
from deephaven import time_table
from deephaven.plugin.matplotlib import TableAnimation

tt = time_table("PT00:00:01").update(
    ["x=i", "y=Math.sin(x)", "z=Math.cos(x)", "r=Math.random()", "s=Math.random()*100"]
)

fig = plt.figure()
ax = fig.subplots()
(line1,) = ax.plot([], [])
(line2,) = ax.plot([], [])
scat = ax.scatter([], [])
scatter_offsets = []
scatter_sizes = []


def update_fig(data, update):
    line1.set_data([data["x"], data["y"]])
    line2.set_data([data["x"], data["z"]])
    added = update.added()
    for i in range(0, len(added["x"])):
        scatter_offsets.append([added["x"][i], added["r"][i]])
        scatter_sizes.append(added["s"][i])
    scat.set_offsets(scatter_offsets)
    scat.set_sizes(scatter_sizes)
    ax.relim()
    ax.autoscale_view(True, True, True)


ani = TableAnimation(fig, tt, update_fig)
```

## Build

To create your build / development environment (skip the first two lines if you already have a venv):

```sh
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip setuptools
pip install build deephaven-plugin matplotlib
```

To build:

```sh
python -m build --wheel
```

The wheel is stored in `dist/`.

To test within [deephaven-core](https://github.com/deephaven/deephaven-core), note where this wheel is stored (using `pwd`, for example).
Then, follow the directions in the top-level README.md to install the wheel into your Deephaven environment.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/deephaven/deephaven-plugins",
    "name": "deephaven-plugin-matplotlib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "deephaven, plugin, matplotlib",
    "author": "Devin Smith",
    "author_email": "devinsmith@deephaven.io",
    "download_url": "https://files.pythonhosted.org/packages/b5/fd/56b38d152d4d0f974f60f6a71cea812e019a64cb7b6b0ca8e31e7599111f/deephaven_plugin_matplotlib-0.4.1.tar.gz",
    "platform": "any",
    "description": "# Deephaven Plugin for Matplotlib\n\nThe Deephaven Plugin for Matplotlib. Allows for opening Matplotlib plots in a Deephaven environment. Any Matplotlib plot\nshould be viewable by default. For example:\n\n```python\nimport matplotlib.pyplot as plt\n\nfig = plt.figure()\nax = fig.subplots()  # Create a figure containing a single axes.\nax.plot([1, 2, 3, 4], [4, 2, 6, 7])  # Plot some data on the axes.\n```\n\nYou can also use `TableAnimation`, which allows updating a plot whenever a Deephaven Table is updated.\n\n## `TableAnimation` Usage\n\n`TableAnimation` is a Matplotlib `Animation` that is driven by updates in a Deephaven Table. Every time the table that\nis being listened to updates, the provided function will run again.\n\n### Line Plot\n\n```python\nimport matplotlib.pyplot as plt\nfrom deephaven import time_table\nfrom deephaven.plugin.matplotlib import TableAnimation\n\n# Create a ticking table with the sin function\ntt = time_table(\"PT00:00:01\").update([\"x=i\", \"y=Math.sin(x)\"])\n\nfig = plt.figure()  # Create a new figure\nax = fig.subplots()  # Add an axes to the figure\n(line,) = ax.plot(\n    [], []\n)  # Plot a line. Start with empty data, will get updated with table updates.\n\n# Define our update function. We only look at `data` here as the data is already stored in the format we want\ndef update_fig(data, update):\n    line.set_data([data[\"x\"], data[\"y\"]])\n\n    # Resize and scale the axes. Our data may have expanded and we don't want it to appear off screen.\n    ax.relim()\n    ax.autoscale_view(True, True, True)\n\n\n# Create our animation. It will listen for updates on `tt` and call `update_fig` whenever there is an update\nani = TableAnimation(fig, tt, update_fig)\n```\n\n### Scatter Plot\n\nScatter plots require data in a different format that Line plots, so need to pass in the data differently.\n\n```python\nimport matplotlib.pyplot as plt\nfrom deephaven import time_table\nfrom deephaven.plugin.matplotlib import TableAnimation\n\ntt = time_table(\"PT00:00:01\").update(\n    [\"x=Math.random()\", \"y=Math.random()\", \"z=Math.random()*50\"]\n)\n\nfig = plt.figure()\nax = fig.subplots()\nax.set_xlim(0, 1)\nax.set_ylim(0, 1)\nscat = ax.scatter([], [])  # Provide empty data initially\nscatter_offsets = []  # Store separate arrays for offsets and sizes\nscatter_sizes = []\n\n\ndef update_fig(data, update):\n    # This assumes that table is always increasing. Otherwise need to look at other\n    # properties in update for creates and removed items\n    added = update.added()\n    for i in range(0, len(added[\"x\"])):\n        # Append new data to the sources\n        scatter_offsets.append([added[\"x\"][i], added[\"y\"][i]])\n        scatter_sizes.append(added[\"z\"][i])\n\n    # Update the figure\n    scat.set_offsets(scatter_offsets)\n    scat.set_sizes(scatter_sizes)\n\n\nani = TableAnimation(fig, tt, update_fig)\n```\n\n### Multiple Series\n\nIt's possible to have multiple kinds of series in the same figure. Here is an example driving a line and a scatter plot:\n\n```python\nimport matplotlib.pyplot as plt\nfrom deephaven import time_table\nfrom deephaven.plugin.matplotlib import TableAnimation\n\ntt = time_table(\"PT00:00:01\").update(\n    [\"x=i\", \"y=Math.sin(x)\", \"z=Math.cos(x)\", \"r=Math.random()\", \"s=Math.random()*100\"]\n)\n\nfig = plt.figure()\nax = fig.subplots()\n(line1,) = ax.plot([], [])\n(line2,) = ax.plot([], [])\nscat = ax.scatter([], [])\nscatter_offsets = []\nscatter_sizes = []\n\n\ndef update_fig(data, update):\n    line1.set_data([data[\"x\"], data[\"y\"]])\n    line2.set_data([data[\"x\"], data[\"z\"]])\n    added = update.added()\n    for i in range(0, len(added[\"x\"])):\n        scatter_offsets.append([added[\"x\"][i], added[\"r\"][i]])\n        scatter_sizes.append(added[\"s\"][i])\n    scat.set_offsets(scatter_offsets)\n    scat.set_sizes(scatter_sizes)\n    ax.relim()\n    ax.autoscale_view(True, True, True)\n\n\nani = TableAnimation(fig, tt, update_fig)\n```\n\n## Build\n\nTo create your build / development environment (skip the first two lines if you already have a venv):\n\n```sh\npython -m venv .venv\nsource .venv/bin/activate\npip install --upgrade pip setuptools\npip install build deephaven-plugin matplotlib\n```\n\nTo build:\n\n```sh\npython -m build --wheel\n```\n\nThe wheel is stored in `dist/`.\n\nTo test within [deephaven-core](https://github.com/deephaven/deephaven-core), note where this wheel is stored (using `pwd`, for example).\nThen, follow the directions in the top-level README.md to install the wheel into your Deephaven environment.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Deephaven Plugin for matplotlib",
    "version": "0.4.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/deephaven/deephaven-plugins/issues",
        "Homepage": "https://github.com/deephaven/deephaven-plugins",
        "Source Code": "https://github.com/deephaven/deephaven-plugins"
    },
    "split_keywords": [
        "deephaven",
        " plugin",
        " matplotlib"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "910f9deee551ec38fe52d1d6df1457aeafe78b81c2d654dea979df91100fed4b",
                "md5": "930a4dbdde540dcd2eb8e15bd38cbd8f",
                "sha256": "90d6dcc86771315a5201229637a4fcca3d2adb19e6a548925f3f87cce629262c"
            },
            "downloads": -1,
            "filename": "deephaven_plugin_matplotlib-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "930a4dbdde540dcd2eb8e15bd38cbd8f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 19976,
            "upload_time": "2024-05-16T17:43:02",
            "upload_time_iso_8601": "2024-05-16T17:43:02.935734Z",
            "url": "https://files.pythonhosted.org/packages/91/0f/9deee551ec38fe52d1d6df1457aeafe78b81c2d654dea979df91100fed4b/deephaven_plugin_matplotlib-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b5fd56b38d152d4d0f974f60f6a71cea812e019a64cb7b6b0ca8e31e7599111f",
                "md5": "8f14bb3b33ca8e4907d4d63899c2ccd5",
                "sha256": "49a7922c81a1b12e46373b6455647c482c782f84b00fa4962ab1df5cd429c61b"
            },
            "downloads": -1,
            "filename": "deephaven_plugin_matplotlib-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8f14bb3b33ca8e4907d4d63899c2ccd5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19546,
            "upload_time": "2024-05-16T17:43:04",
            "upload_time_iso_8601": "2024-05-16T17:43:04.758954Z",
            "url": "https://files.pythonhosted.org/packages/b5/fd/56b38d152d4d0f974f60f6a71cea812e019a64cb7b6b0ca8e31e7599111f/deephaven_plugin_matplotlib-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-16 17:43:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "deephaven",
    "github_project": "deephaven-plugins",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "deephaven-plugin-matplotlib"
}
        
Elapsed time: 0.24019s