Skip to main content

Deephaven Plugin for matplotlib

Project description

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:

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

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("00: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.

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

tt = time_table("00: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:

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

tt = time_table("00: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:

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

To build:

python -m build --wheel

produces the wheel into dist/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deephaven-plugin-matplotlib-0.1.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deephaven_plugin_matplotlib-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file deephaven-plugin-matplotlib-0.1.1.tar.gz.

File metadata

File hashes

Hashes for deephaven-plugin-matplotlib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1b0bbd5a292d96abbe2af05ccabeab015fc8362b5d558fee76c0060a49f0c708
MD5 011887b934b686f0e0d4ef0cea49b7f4
BLAKE2b-256 c2dc933815099321e1ae2553690a848ea9bef251c155c4f700edf1b36537e282

See more details on using hashes here.

File details

Details for the file deephaven_plugin_matplotlib-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for deephaven_plugin_matplotlib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5592441e6d99a6ee4f3af910f2abacbe6ca4be08100915f703fb700b85c324d
MD5 58ddef06de1f1d26879caa3165a026a4
BLAKE2b-256 85963e61b289e225f6cfea48902e64c150cf7dd8b007fccd8705555c5a442fdd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page