Matplotlib的Deephaven插件
项目描述
Matplotlib的Deephaven插件
Matplotlib的Deephaven插件。允许在Deephaven环境中打开Matplotlib图表。任何Matplotlib图表都应该默认可查看。例如
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.
您还可以使用TableAnimation
,它允许在Deephaven Table更新时更新图表。
TableAnimation
用法
TableAnimation
是一个由Deephaven Table中的更新驱动的Matplotlib Animation
。每当正在监听的表更新时,提供的函数将再次运行。
折线图
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)
散点图
散点图需要的数据格式与折线图不同,因此需要以不同的方式传递数据。
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)
多个系列
在同一个图中可以有多种类型的系列。以下是一个示例,展示了如何驱动折线图和散点图。
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)
构建
为了创建您的构建/开发环境(如果您已经有了一个venv,请跳过前两行)
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip setuptools
pip install build deephaven-plugin matplotlib
构建
python -m build --wheel
轮文件存储在dist/
中。
在deephaven-core中测试时,请注意轮文件的存储位置(例如使用pwd
)。然后,按照顶级README.md中的说明将轮文件安装到您的Deephaven环境中。
项目详情
关闭
哈希值 for deephaven_plugin_matplotlib-0.5.0-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 02e3bd55e4d67527d6632b4cbba131a0f264459254d4cf2df5050ecfe098e1f0 |
|
MD5 | ad47cbac2b49f111cc3d6bc8aca2bba1 |
|
BLAKE2b-256 | a5f9ead0a1e7cd08dd2ec4436b6076bc091c4fb9e7d5acc1843ad693582fbd70 |