I would like to label data points in pandas with x axis value. And I am trying to apply this solution into my code: Annotate data points while plotting from Pandas DataFrame
I'm getting an error saying:
AttributeError: 'PathCollection' object has no attribute 'text'
Here's my code:
def draw_scatter_plot(xaxis, yaxis, title, xaxis_label, yaxis_label, save_filename, color, figsize=(9, 7), dpi=100):
fig = plt.figure(figsize=figsize, dpi=dpi)
ax = plt.scatter(xaxis, yaxis, c=color)
plt.xlabel(xaxis_label)
plt.ylabel(yaxis_label)
label_point(xaxis, yaxis, xaxis, ax)
plt.title(title)
fig.savefig(save_filename, dpi=100)
# label code from https://stackoverflow.com/questions/15910019/annotate-data-points-while-plotting-from-pandas-dataframe/15911372#15911372
def label_point(x, y, val, ax):
a = pd.concat({'x': x, 'y': y, 'val': val}, axis=1)
for i, point in a.iterrows():
ax.text(point['x'], point['y'], str(point['x']))
Any advice on this problem?