I have the following data frame:
dates = [pd.Timestamp('2010-01-01T12:10:30'), pd.Timestamp('2010-01-01T12:10:35'), pd.Timestamp('2010-01-01T12:10:40')]
df = pd.DataFrame({'ref_date': dates, 'x': [1, 3, 2]}).set_index('ref_date')
How do I add each x-value as text on the plot? If the x-axis weren't a time series, then I could have looped through each value and use ax.text()
, but I don't know how to do that when I have timestamps instead, i.e. I don't know how to calculate the (x, y) coordinate for the text.
sns.scatterplot(data=df)
EDIT:
Is there a way we can dynamically make labels not overlap? For example, consider adding this extra point to the above df
: pd.Timestamp('2010-01-01T12:10:30.001')
and 1.03
.