Harxish
Harxish

Reputation: 459

Plotly adds slash after annotation

I'm trying to add annotations to gantt charts in plotly. But weirdly plotly adds a slash to the annotated text in the next line. I'm confident that the text field in my annotation is correct and doesn't contain slashes.

Data:

rect = [{'Task': 'Task 1', 'Start': datetime.datetime(2021, 5, 5, 14, 4, 47, 398000), 'Finish': datetime.datetime(2021, 5, 5, 14, 4, 47, 482000), 'duration': '00:00.084'},
        {'Task': 'Task 2', 'Start': datetime.datetime(2021, 5, 5, 14, 4, 47, 545000), 'Finish': datetime.datetime(2021, 5, 5, 14, 4, 47, 579000), 'duration': '00:00.034'},
        {'Task': 'Task 3', 'Start': datetime.datetime(2021, 5, 5, 14, 4, 47, 583000), 'Finish': datetime.datetime(2021, 5, 5, 14, 5, 0, 980000), 'duration': '00:13.397'}]

Annotations:

annots = [{'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 398000), 'y': 125.5, 'text': '8', 'font': {'color': 'black'}},
          {'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 545000), 'y': 123.5, 'text': '3', 'font': {'color': 'black'}},
          {'x': datetime.datetime(2021, 5, 5, 14, 4, 47, 583000), 'y': 120.5, 'text': '9', 'font': {'color': 'black'}}]

Code:

rect = px.timeline(rect, x_start="Start", x_end="Finish", y="Task", hover_data=hover_data1, hover_name=hover_name)
rect.update_traces(marker=dict(line=dict(width=1, color='black')))
rect.update_xaxes(tickformat="%H:%M:%S.%L", tickmode='linear', dtick='120000')
rect.update_yaxes(showgrid=True, autorange=False, categoryorder='array', categoryarray=labels[::-1], range=[-1, len(labels)+.5])
rect.update_layout(title=title, showlegend=False, height=2800, width=2000, annotations=annots)

Graph:

Plot Image

The slash appears on the next line.

Thanks :)

Upvotes: 1

Views: 411

Answers (1)

Derek O
Derek O

Reputation: 19590

Plotly annotations show arrows by default - this can be seen in the documentation here. To turn this off, add the following line to the end of the your code (after you have added the annotations):

rect.update_annotations(showarrow=False)

Upvotes: 3

Related Questions