question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Hi, I am trying to use the library for a simple visualisation for the first time, and I stumbled upon supposedly a bug trying to draw a vertical line with text annotation on a graph with a date-time x axis.

import plotly.express as px
df = px.data.stocks(indexed=True)
fig = px.line(df)
fig.add_vline(x="2018-09-24", annotation_text="test" )
fig.show()

I get the following error message:

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

Could anyone please help me confirm that it is indeed a bug, my version is ‘4.14.1’ ? Thank you.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:24
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
awrobel1commented, Feb 13, 2021

Hi @MR0205,

If you’re looking for a temporary workaround, you can get the annotation to work by converting your x value into milliseconds since epoch as follows:

import plotly.express as px
import datetime
df = px.data.stocks(indexed=True)
fig = px.line(df)
fig.add_vline(x=datetime.datetime.strptime("2018-09-24", "%Y-%m-%d").timestamp() * 1000, annotation_text="test" )
fig.show()
7reactions
tomshaffnercommented, Jun 2, 2021

The above suggestion from @awrobel1 was great for me. In my case I simplified a tad with x=datetime.datetime(2021,5,27).timestamp() * 1000. No need to convert from a string first in this case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add_vline with annotation and datetime as x-axis - Plotly Python
I'm using datetime objects as x-axis values, no problem there. ... Error on using add_vline with text annotation for data with date-time x ......
Read more >
Adding annotation text yields integer error message
When I adding a vline to my graph it works perfect: fig.add_vline( x=pd.
Read more >
Error on using add_vline with text annotation for data with date ...
Error on using add_vline with text annotation for data with date-time x axis ... Hi, I am trying to use the library for...
Read more >
Releases — HoloViews v1.15.3
Fixed xaxis/yaxis options with Matplotlib (#5200). Fixed nested widgets by handling list or ... Fix Bars legend error when overlaid with annotation (#5142)....
Read more >
Convert Unix Timestamp With Bokeh Plotting X Axis - ADocLib
When I plot using fplt.plotdf['timestamp' df['MyIndicator']] the x axis ... Error on using addvline with text annotation for data with datetime x axis...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found