Skip to content

[Bug] add_hline and add_vline do not work with datetime and annotation_text #3494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hidr0 opened this issue Dec 2, 2021 · 3 comments
Closed

Comments

@hidr0
Copy link

hidr0 commented Dec 2, 2021

I am trying to show an hline or vline on a time series.

import datetime
import plotly.graph_objects as go
figure = go.Figure()

figure.update_layout(
    yaxis=dict(
        type="date",
        tickformat='%H:%M',
    )
)

figure.add_hline(
    annotation_text="Recommended Daily Intake",
    y=datetime.datetime.now(),
)

The error I get:

  File "..../.venv/lib/python3.9/site-packages/plotly/shapeannotation.py", line 7, in _mean
    return float(sum(x)) / len(x)
TypeError: unsupported operand type(s) for +: 'int' and 'datetime.datetime'

x is:

>>> print(x)
[datetime.datetime(2021, 12, 2, 14, 3, 29, 780450), datetime.datetime(2021, 12, 2, 14, 3, 29, 780450)]

Which means that sum does not work with datetime.datetime:

>>> sum([datetime.datetime(2021, 12, 2, 14, 3, 29, 780450), datetime.datetime(2021, 12, 2, 14, 3, 29, 780450)])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'datetime.datetime'
@pratikmondkar
Copy link

Facing the same issue. This feature is especially useful for facet grids since it avoids having to add annotations for each facet individually

@Uberi
Copy link

Uberi commented Mar 6, 2022

Looks like this is related to #3065, which also has a workaround!

@gvwilson
Copy link
Contributor

gvwilson commented Jul 3, 2024

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

@gvwilson gvwilson closed this as completed Jul 3, 2024
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

No branches or pull requests

4 participants