
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to plot certain rows of a Pandas dataframe using Matplotlib?
To plot certain rows of a Pandas dataframe, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a Pandas data frame, df. It should be a two-dimensional, size-mutable, potentially heterogeneous tabular data.
- Make rows of Pandas plot. Use iloc() function to slice the df and print specific rows.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt import numpy as np import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.randn(10, 5), columns=list('abcde')) df.iloc[0:6].plot(y='e') print(df.iloc[0:6]) # plt.show()
Output
We have 10 rows in the dataframe. When we execute the code, it will print the first 6 rows on the console because iloc[0:6] slices the first 6 rows from the dataframe.
a b c d e 0 1.826023 0.606137 0.389687 -0.497605 0.164785 1 0.571941 2.324981 -1.154445 0.757724 0.570713 2 -1.328481 1.248171 -0.849694 -1.133029 -0.977927 3 -0.509296 1.086251 0.809288 0.409166 -0.080694 4 0.973164 1.328212 0.858214 0.997309 -0.375427 5 1.014649 1.480790 -1.451903 -0.306659 -0.382312
To plot this sliced dataframe, uncomment the last line plt.show() in the code and execute it again.
- Related Articles
- How to plot a Pandas Dataframe with Matplotlib?
- Frequency plot in Python/Pandas DataFrame using Matplotlib
- How to change the DPI of a Pandas Dataframe Plot in Matplotlib?
- How to plot an area in a Pandas dataframe in Matplotlib Python?
- How to plot a Pandas multi-index dataFrame with all xticks (Matplotlib)?
- Annotating points from a Pandas Dataframe in Matplotlib plot
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Plot a Line Graph for Pandas Dataframe with Matplotlib?
- How to plot a kernel density plot of dates in Pandas using Matplotlib?
- Python - Plot a Pie Chart for Pandas Dataframe with Matplotlib?
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to plot a time as an index value in a Pandas dataframe in Matplotlib?
- Plot multiple columns of Pandas DataFrame using Seaborn
- Python Pandas - How to append rows to a DataFrame
- How to append new rows to DataFrame using a Template In Python Pandas

Advertisements