- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to annotate the points on a scatter plot with automatically placed arrows in Matplotlib?
To annotate the point on a scatter plot with automatically placed arrows, we can take the following steps −
Create points for x and y using numpy.
Create labels using xpoints.
Use scatter() method to scatter the points.
Iterate labels, xpoints and ypoints and annotate plot with label, x and y with different properties.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True xpoints = np.linspace(1, 10, 25) ypoints = np.random.rand(25) labels = ["%.2f" % i for i in xpoints] plt.scatter(xpoints, ypoints, c=xpoints) for label, x, y in zip(labels, xpoints, ypoints): plt.annotate( label, xy=(x, y), xytext=(-20, 20), textcoords='offset points', ha='right', va='bottom', bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5), arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0') ) plt.show()
Output
- Related Articles
- How to plot additional points on the top of a scatter plot in Matplotlib?
- Plot scatter points on polar axis in Matplotlib
- Plot scatter points on a 3D projection with varying marker size in Matplotlib
- How to plot scatter points in a 3D figure with a colorbar in Matplotlib?
- Plot scatter points using plot method in Matplotlib
- How to plot scatter points with increasing size of marker in Matplotlib?
- Plot scatter points on 3d plot without axes and grids in Matplotlib
- Line plot with arrows in Matplotlib
- Connecting two points on a 3D scatter plot in Python and Matplotlib
- How to annotate several points with one text in Matplotlib?
- How to animate a scatter plot in Matplotlib?
- How to use different markers for different points in a Pylab scatter plot(Matplotlib)?
- How to shade points in a scatter based on colormap in Matplotlib?
- How to plot scatter masked points and add a line demarking masked regions in Matplotlib?
- Annotate Time Series plot in Matplotlib

Advertisements