Error using add_vline+annotation_text with a dataframe with DateTimeIndex

Hi there and thanks for this nice graphing library! It works very nice for me! See code below: Using add_vline + annotation_text however seems not to work on a dataframe using a DateTimeIndex: ā€œunsupported operand type(s) for +: ā€˜intā€™ and ā€˜strā€™ā€.

Am I doing something wrong? Or is this a bug? If so: Where can I report the bug? I am using version 4.14.3

import os
import pandas as pd
import numpy as np
import plotly.express as px 

working_dir = os.path.dirname(os.path.abspath(__file__))

# Normal Index: vline and annotation okay
rng = pd.date_range('2015-02-24', periods=5, freq='T')
df = pd.DataFrame({ 'Date': rng, 'Val': np.random.randn(len(rng)) })
fig = px.line(df, x=df.index, y='Val')
fig.add_vline(1, line_dash="dash", annotation_text="Test")
fig.write_html(working_dir+r"\test_vline_1.html")

# Datetime-Index: vline without annotation okay
rng = pd.date_range('2015-02-24', periods=5, freq='T')
df = pd.DataFrame({ 'Val' : np.random.randn(len(rng)) }, index=rng) 
fig = px.line(df, x=df.index, y='Val')
fig.add_vline('2015-02-24 00:01:00')
fig.write_html(working_dir+r"\test_vline_2.html")

# Datetime-Index: vline with annotation triggers an error
rng = pd.date_range('2015-02-24', periods=5, freq='T')
df = pd.DataFrame({ 'Val' : np.random.randn(len(rng)) }, index=rng) 
fig = px.line(df, x=df.index, y='Val')
fig.add_vline('2015-02-24 00:01:00', annotation_text="Test")
fig.write_html(working_dir+r"\test_vline_3.html")

Any solution yet?

Iā€™m getting exactly the same error, nevertheless while using fig.add_hline the annotations work just fine!

Anything else on this? im also getting the same error

Hi there! The same for me. add_vline works perfectly fine until I try to add the annotation_textā€¦ Any fix?

Yeah I just ran into the same thing! Whatā€™s up with that? Horizontal lines work fine with annotations but not vertical.

works

df = px.data.stocks(indexed=True)
fig = px.line(df)
fig.add_hline(y=1, line_dash="dot",
              annotation_text="Jan 1, 2018 baseline", 
              annotation_position="bottom right")
fig.show()

doesnā€™t work :confused:

df = px.data.stocks(indexed=True)
fig = px.line(df)
fig.add_hline(y=1, line_dash="dot",
              annotation_text="Jan 1, 2018 baseline", 
              annotation_position="bottom right")
fig.show()

One work-around is to use a add_vrect and make the width of the rectangle really small:

df = px.data.stocks(indexed=True)
fig = px.line(df)
fig.add_vrect(x0="2018-09-24", x1="2018-09-25", 
              annotation_text="decline", annotation_position="top left",
              fillcolor="green", opacity=0.25, line_width=0)
fig.show()

But this ought to be fixed :hammer_and_wrench: