✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🏦 Standard & Poor's chooses Dash Enterprise for ESG analysis. Learn why, sign up for the June 23 Webinar here!

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?