Skip to content

Fix add_vline and add_hline with datetime axes#5508

Open
mosh3eb wants to merge 1 commit intoplotly:mainfrom
mosh3eb:fix/add-vline-datetime-annotation
Open

Fix add_vline and add_hline with datetime axes#5508
mosh3eb wants to merge 1 commit intoplotly:mainfrom
mosh3eb:fix/add-vline-datetime-annotation

Conversation

@mosh3eb
Copy link

@mosh3eb mosh3eb commented Feb 14, 2026

When using add_vline with annotation_text on datetime axes, plotly was crashing with a TypeError because the _mean() helper function tried to sum date strings.

Since vlines have x0==x1 and hlines have y0==y1, we can just return the first value when sum() fails on non-numeric data. This fixes the issue while maintaining full backward compatibility.

Fixes #3065

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the code generator and not the generated files.
  • I have added tests or modified existing tests.
  • For a new feature, I have added documentation examples (please see the doc checklist as well).
  • I have added a CHANGELOG entry if changing anything substantial.
  • For a new feature or a change in behavior, I have updated the relevant docstrings in the code.

When using add_vline with annotation_text on datetime axes, plotly
was crashing with a TypeError because the _mean() helper function
tried to sum date strings.

Since vlines have x0==x1 and hlines have y0==y1, we can just return
the first value when sum() fails on non-numeric data. This fixes the
issue while maintaining full backward compatibility.

Fixes plotly#3065
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error on using add_vline with text annotation for data with date-time x axis

1 participant