Skip to content

Bug: Exceptions thrown following User Interaction with Annotations on a time axis #4961

Open
@bcliang

Description

@bcliang

In my use case, a user may load time-series data into a scatter chart. The user may need to zoom and pan the time axis of the plot (xtickmode='auto' with nticks=#) to better visualize periods of data.

  • Users may wish to annotate the plots (using a rect or line drawing) -- they do so by clicking the annotation buttons on the plotly figure toolbar.
  • In some cases, an annotation is placed incorrectly on the time axis and must be moved/resized. In this case, users select an annotation and then drag-drop as appropriate.

Regression in v5.23.0

  • In plotly.py v5.22.0: when drawing a figure with at least one time axis, annotations could be moved/resized interactively without problem. (expected behavior)
  • With v5.23.0 a regression was introduced. Moving/resizing an annotation will trigger browser exception (ERROR: unrecognized date (NaN)) when working on a time axis. The annotation will disappear from the figure with the exception.
  • minimal reproducible examples below:

This only affects time-axis (no issues when both x- and y-axes are numerical)

import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame({
        "id": [1, 2, 3, 4, 5],
        "data1": [1, 2, 3, 4, 5],
    })

fig = go.Figure()
fig.add_trace(
    go.Scatter(
        x = df.id,
        y = df.data1
    ),
)
fig.update_layout(title=dict(text="no problems resizing/moving annotations after selection"))

fig.show(config=dict(
        modeBarButtonsToAdd=[
            "drawline",
            "drawrect",
        ],
    ),
)

exceptions when x- or y-axis is a datetime object

Note: also the case with pd.Timestamp object

import pandas as pd
import plotly.graph_objects as go
import datetime

df2 = pd.DataFrame({
        "id": [datetime.datetime(2024, 11, 1 + index) for index in range(5)],
        "data1": [1, 2, 3, 4, 5],
    })

fig2 = go.Figure()
fig2.add_trace(
    go.Scatter(
        x = df2.id,
        y = df2.data1,
    ),
)
fig2.update_layout(title=dict(text="(x axis) invalid date error on resize/move annotation"))
fig2.show(
    config=dict(
        modeBarButtonsToAdd=[
            "drawline",
            "drawrect",
        ],
    ),
)

fig2b = go.Figure()
fig2b.add_trace(
    go.Scatter(
        x = df2.data1,
        y = df2.id
    ),
)
fig2b.update_layout(title=dict(text="(y axis) invalid date error on resize/move annotation"))
fig2b.show(config=dict(
        modeBarButtonsToAdd=[
            "drawline",
            "drawrect",
        ],
    ),
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclebugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions