# Gantt plot with annotations on bar

**URL:** <https://community.plotly.com/t/gantt-plot-with-annotations-on-bar/43565>\
**Category:** 📊 Plotly Python\
**Created:** [August 9, 2020, 4:06am UTC](https://community.plotly.com/t/gantt-plot-with-annotations-on-bar/43565 "2020-08-09T04:06:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JessicaKuo](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@JessicaKuo](https://community.plotly.com/u/JessicaKuo)\
**Post date:** [August 9, 2020, 4:06am UTC](https://community.plotly.com/t/gantt-plot-with-annotations-on-bar/43565/1 "2020-08-09T04:06:00Z")

</div>

Hello,

I encountered a problem when adding annotations on my Gantt chart, like the figure below:

 ![plotly_gantt_chart_annotation_issue](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/f/fd4160c56681380331c2604cb4a9bc90cffe6d61.png)

The problem is that the location of annotations is not where I want them to be. Currently, the annotations is on the top of figure with correct x-axis positions, yet their y-axis positions are not what I want. I hope they can be located **(1) on the bar (if the font color is white)** or **(2) beside the bar (if font color is blue)**.

The idea is something like this:

 ![plotly_gantt_chart_annotation_wanted-result](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/4/4605f9ef6552965fc59183bed6f194287998c962.png)

The dataframe I used is this:

![gantt plot df](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/7/7e2757bd63ab4cde08a43b9a8d719be05187bb2e.png)

The code I wrote is attached here:

```auto
import pandas as pd
import plotly.figure_factory as ff

df = pd.read_csv('drug_timeline.csv')
df['start']=pd.to_datetime(df['start'].astype(str), format='%Y%m%d').dt.strftime('%Y-%m-%d')
df['finish']=pd.to_datetime(df['finish'].astype(str), format='%Y%m%d').dt.strftime('%Y-%m-%d')

df['Start'] = df['start']
df['Finish'] = df['finish']
df['Task'] = df['drug_id']
dig = ff.create_gantt(df, group_tasks=True,index_col='drug_id')

fig.show()

```

```auto
fig.update_layout(
    title='Medication Rx',
    yaxis=dict(
        showgrid=False,
        showline=False,
        showticklabels=True,
        domain=[0, 0.9],
    ),
    xaxis=dict(
        zeroline=False,
        showline=False,
        showticklabels=True,
        showgrid=True,
        domain=[0, 0.8],
    ),
    margin=dict(l = 50, r = 50, b = 50, t = 50, pad = 4),
)
dosage= df['usage']
drug = df['drug_id']
date=df['start']

annotations1=[]
for xdn,yd, xd in list(zip(date,dosage,drug)):
    annotations1.append (dict(
                            y=xd, x=xdn,
                            text=str(yd),
                            font=dict(family='consolas', size=12,color='rgb(0,0,205)'),
                            align='left',
                            ))
fig.update_layout(annotations=annotations1,margin=dict(l = 50, r = 50, b = 50, t = 50, pad = 4))
fig.show()

```

I would like to thank you for your time reading through my problem.

Please let me know any suggestions regarding this annotation issue.
