0

I'm new to using Seaborn library.

I want to see each data point labelled with black text in the graph itself (beside data points), by manually appending a new column to results. How do I do this? How do I pass a 3rd column (labels) as a parameter?

import seaborn as sns

sns.scatterplot(x=results[:, 0], y=results[:, 1], alpha=1, s=100).plot()
fig = plt.gcf()
plt.scatter(x=results[:, 0], y=results[:, 1])
plt.draw()
plt.show()

The data I am passing in results:

results = [[-0.01951522, 0.01933503]
 [-0.01793732, 0.01350751]
 [ 0.00615655, 0.00632767]
 [-0.0585989, -0.00142193]
 [-0.0348609 , 0.00997727]
 [ 0.10552081, -0.00200007]
 [ 0.1394851, -0.00433918]
 [-0.04782358, -0.01110567]
 [ 0.0211212, 0.01102468]
 [ 0.04887021, -0.00828152]
 [ 0.08460241, 0.00123756]
 [-0.02598796, -0.00897868]
 [-0.05668114, -0.00262177]
 [ 0.02583048, -0.01067982]
 [-0.10160218, -0.00816926]
 [-0.06857958, -0.00381181]]

This is what the output currently looks like: Seaborn Scatterplot

2 Answers2

0

See this question. You might want to google your question first next time.

  • I did see this. However, this isn't what I have asked but does yield the same outcome. –  Mar 11 '21 at 19:51
  • Reading your question, I assumed you wanted to add labels to your plot. After reading it a second time and your comment, I understand you want to pass an additional argument so that labels will appear magically. This is obviously not how it works. You can read the [documentation](https://seaborn.pydata.org/generated/seaborn.scatterplot.html) of the `seaborn.scatterplot` function. Also, if it were that simple, wouldn't you expect that to be the top answer to the other question? – Gilles Ottervanger Mar 11 '21 at 19:56
0

The Seaborn package does not provide an API for annotation, but thankfully Seaborn is built on top of Matplotlib , which does.
To add annotation you can use the .text(x, y, s) function, which specifies the x,y coordinates as float and text as str.

import seaborn as sns
import numpy as np

results = np.array([[-0.01951522, 0.01933503], [-0.01793732, 0.01350751],[ 0.00615655, 0.00632767],[-0.0585989, -0.00142193],[-0.0348609 , 0.00997727],[ 0.10552081, -0.00200007],[ 0.1394851, -0.00433918],[-0.04782358, -0.01110567],[ 0.0211212, 0.01102468],[ 0.04887021, -0.00828152],[ 0.08460241, 0.00123756],[-0.02598796, -0.00897868],[-0.05668114, -0.00262177],[ 0.02583048, -0.01067982],[-0.10160218, -0.00816926],[-0.06857958, -0.00381181]])

ax = sns.scatterplot(x= results[:, 0], y=results[:, 1], alpha=1, s=100)
s = [str(x) for x in range(1, len(results))]
for point in range(0, len(results)-1):
    ax.text(x=results[point, 0]+0.003, y=results[point, 1]-0.0012, s=s[point])

scatter plot with annotation

jbadger3
  • 26
  • 3