- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Annotate data points while plotting from Pandas DataFrame
To annotate data points while plotting from pandas data frame, we can take the following steps −
Create df using DataFrame with x, y and index keys.
Create a figure and a set of subplots using subplots() method.
Plot a series of data frame using plot() method, kind='scatter', ax=ax, c='red' and marker='x'.
To annotate the scatter point with the index value, iterate the data frame.
To display the figure, use show() method.
Example
import numpy as np import pandas as pd from matplotlib import pyplot as plt import string plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'x': np.random.rand(10), 'y': np.random.rand(10)}, index=list(string.ascii_lowercase[:10])) fig, ax = plt.subplots() df.plot('x', 'y', kind='scatter', ax=ax, c='red', marker='x') for k, v in df.iterrows(): ax.annotate(k, v) plt.show()
Output
- Related Articles
- Annotating points from a Pandas Dataframe in Matplotlib plot
- Plotting error bars from a dataframe using Seaborn FacetGrid (Matplotlib)
- Python - Convert Pandas DataFrame to binary data
- Python Pandas - Create Multiindex from dataframe
- Python – Reshape the data in a Pandas DataFrame
- Python – Strip whitespace from a Pandas DataFrame
- Python Pandas - Plot multiple data columns in a DataFrame?
- How to check the data type in pandas DataFrame?
- Plotting a histogram from pre-counted data in Matplotlib
- Python - Drop specific rows from multiindex Pandas Dataframe
- Selecting with complex criteria from a Pandas DataFrame
- Python - Remove duplicate values from a Pandas DataFrame
- How to delete a column from Pandas DataFrame
- Python - Select multiple columns from a Pandas dataframe
- Fetch only capital words from DataFrame in Pandas

Advertisements