[BUG] numpy array not correctly read back from figure data
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- numpy, plotly, python
调研方向
首先使用 Python 3.12、numpy 2.2.5、plotly 6.1.1 以及列出的 Dash 版本运行提供的 Dash 复现,然后检查通过 callback State 返回的 figure 数据。将 x 和 y 值与原始数组进行比较;当不支持的数组引发异常,或以 numpy 数组或有效列表的形式返回时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Please provide us your environment, so we can easily reproduce the issue:
Windows 10, python 3.12
dash 3.0.4
dash-core-components 2.0.0
dash-html-components 2.0.0
plotly 6.1.1
numpy 2.2.5
Describe the bug
When I create a go.Figure and add a trace with x and/or y being numpy arrays, the plot is created correctly.
However, when I want to read back the data, some representation of the numpy array is provided as dictionary: {‘dtype’: ‘f8’, ‘bdata’: ‘AAAAAAAA8D8AAAAAAAAAQAAAAAAAAAhAAAAAAAAAEEAAAAAAAAAUQA==’, ‘_inputArray’: {‘0’: 1, ‘1’: 2, ‘2’: 3, ‘3’: 4, ‘4’: 5, ‘bdata’: ‘AAAAAAAA8D8AAAAAAAAAQAAAAAAAAAhAAAAAAAAAEEAAAAAAAAAUQA==’, ‘dtype’: ‘f8’, ‘shape’: ‘5’}}
As also described in https://community.plotly.com/t/changed-behaviour-in-dash-2-18-2-using-numpy-1-26-4-when-reading-figure-into-callback-on-linux/90614
import dash
from dash import dcc, html, Input, Output, State
import plotly.graph_objs as go
import numpy as np
# Initialize the Dash app
app = dash.Dash(__name__)
# Create some sample data using numpy
x_data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
y_data = np.array([2.0, 1.5, 3.5, 2.0, 5.0])
# Define the layout of the app
app.layout = html.Div([
dcc.Graph(id='scatter-plot'),
html.Button('Generate Plot', id='generate-button', n_clicks=0),
html.Button('Print Data', id='print-button', n_clicks=0)
])
# Callback to generate the ScatterGL plot
@app.callback(
Output('scatter-plot', 'figure'),
Input('generate-button', 'n_clicks')
)
def update_figure(n_clicks):
# Create a ScatterGL trace
trace = go.Scattergl(
x=x_data,
y=y_data,
mode='markers',
marker=dict(size=10, color='blue')
)
# Create the figure
fig = go.Figure(data=[trace])
fig.update_layout(title='ScatterGL Plot', xaxis_title='X Axis', yaxis_title='Y Axis')
return fig
# Callback to print the x and y data from the figure
@app.callback(
Output('print-button', 'children'),
Input('print-button', 'n_clicks'),
State('scatter-plot', 'figure')
)
def print_data(n_clicks, figure):
if n_clicks > 0 and figure is not None:
# Extract the x and y data from the figure
x_values = figure['data'][0]['x']
y_values = figure['data'][0]['y']
# Print the x and y values
print("X values:", x_values)
print("Y values:", y_values)
return "Print Data"
# Run the app
if __name__ == '__main__':
app.run_server(debug=True)
Expected behavior
A) Throw an Exception when numpy arrays are not supported
B) If numpy arrays are supported return the numpy array or the numpy array converted to a valid list
- 主要语言
- Python
- 星标
- 24.5k
- 派生
- 2.3k
- 平均合并
- 3 天 7 小时
- 30 天内合并 PR
- 30
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
plotly/dash 的其他 Issue
-
P2 plotly-internal size: 1 task
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Extract graph schema validation into properly named test可能已有人在做 @Nice6042 于 90 天前认领。 未关闭good first issue P3 size: 1 task
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
[BUG] Patch.update mutates a shared mapping and rewrites earlier merges可能已有人在做 @peterolkhov 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
维护者通常 1 天内回复
-
[BUG] dcc.Dropdown: virtualized list keeps the height measured at opening when options grow while the menu is open可能已有人在做 @KoolADE85 于 2 天前认领。 未关闭bug P3 size: 1
plotly/dash#4131 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[BUG] `set_props` streaming可能已有人在做 @BSd3v 于 5 天前认领。 未关闭bug P3 size: 1
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
[BUG] HTTP lifecycle dispatch treats a NO_PROXY-only environment as corporate egress and skips the resolve-and-pinned session可能已有人在做 @bodapatisaikrishna 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
external
难度 2/5 1-3 小时 新手友好度 65/100
langchain-ai/docs#7652 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
elastic/oblt-aw#2513 · 1 条评论 ·
维护者通常 1 天内回复
-
bug p2
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 75/100
NCAR/CLM-Tutorial#113 · 1 条评论 ·
维护者通常 1 天内回复