✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Error if adding annotation to add_vline on plotly express when x is a datetime

I’m getting the following error when I try to annotate a vline using the “annotate_text” argument in the “add_vline” method:

TypeError: unsupported operand type(s) for +: 'int' and 'datetime.datetime'

The x-value is a datetime.datetime type. If I change the x to float or int, it does not give the error. The behavior is the same on the “add_hline” method.

Full code and error message:

Dug into a bit, was able to get it to work by moving the “_mean” function calls to just before they are needed in the hline and vline blocks. Obviously this is not ideal because it’d require changing the call in multiple places (and would not address angled lines from what I understand of the code).
It looks like (2) values are being passed in for all uses in this file, so would finding the point that is equidistant between the x0 and x1 values provide the expected results?

1 Like