plotly / plotly/plotly.py

Adding N annotations takes O(N^2) time

未关闭
#5,316 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P2 performance
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

Plotly is unreasonably slow to add more than a few hundred annotations to a plot. This code

import time

import plotly


fig = plotly.graph_objects.Figure()

NUM_ANNOTATIONS=1000

start_time = time.monotonic()
for i in range(NUM_ANNOTATIONS):
    fig.add_annotation(
        x=i,
        y=time.monotonic() - start_time,
        text=str(i),
    )
    print(i)
fig.update_layout(
    xaxis_range=[0,NUM_ANNOTATIONS],
    yaxis_range=[0,time.monotonic() - start_time],
    xaxis_title_text="# Annotations",
    yaxis_title_text="Cumulative Time [s]",
)
fig.show()

produces this plot

Image

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行 issue 中的复现脚本,并对重复调用 fig.add_annotation 进行性能分析。跟踪 Python Figure 的注释路径,以确定累积成本增长的位置,然后使用同一个脚本验证添加大量注释不再表现出二次行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
data-visualization, performance
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。