plotly / plotly/plotly.py

Adding N annotations takes O(N^2) time

Open
#5,316 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2 performance
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproduction in the issue and profiling the repeated fig.add_annotation calls. Trace the Python Figure annotation path to identify where the cumulative cost grows, then verify that adding many annotations no longer shows quadratic behavior using the same script.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.