Home »
Python »
Python Programs
How to suppress matplotlib warning?
Learn, how to suppress matplotlib warning in Python?
By Pranit Sharma Last updated : October 06, 2023
Pandas is a special tool that allows us to perform complex manipulations of data effectively and efficiently. Inside pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and data.
Suppressing matplotlib warning
Sometimes while importing pandas, we get a warning from matplotlib which says:
UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
We need to find a way to suppress this warning. For this purpose, we can use warnings.filterwarnings() method and pass ignore parameter inside it this could be possible by importing warnings.
Also, rather than hiding everything, we can also hide specific warnings, for example, if we want to hide only matplotlib warnings we can pass another parameter as:
module=''matplotlib\...*"
Let us understand with the help of an example,
Python program to suppress matplotlib warning
# Importing warnings
import warnings
# Suppress all warnings
warnings.filterwarnings('ignore')
# Supressing only matplotlib warnings
warnings.filterwarnings( "ignore", module = "matplotlib\..*" )
# Importing pandas package
import pandas as pd
Python Pandas Programs »