Basic scatterplot
You can create a basic scatterplot using regplot() function of seaborn library. The following parameters should be provided:
- data : dataset
- x : positions of points on the X axis
- y : positions of points on the Y axis
- fit_reg : if True, show the linear regression fit line
- marker : marker shape
- color : the color of markers
Add one annotation
Once you have created the dataset and plotted the scatterplot with the previous code, you can use text() function of matplotlib to add annotation. The following parameters should be provided:
- x : the position to place the text in x axis
- y : the position to place the text in y axis
- s: the text
You can also specify the additional parameters such as horizontalalignment, size, color, weight to design your text.
Use a loop to annotate each marker
If you want to annotate every markers, it is practical to use a loop as follow:
Going further
This post explains how to customize the appearance of the markers in a scatter plot with seaborn.
You might be interested in:
- customize annotation in matplotlib
- how to create a bubble plot, a kind of scatter plot where the size of the marker is proportional to a third variable
- how to colors dots according to a variable.