37

I am getting an warning from matplotlib every time I import pandas:

/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.


 warnings.warn(self.msg_depr % (key, alt_key))

What is the best way to suppress it? All packages are up-to-date.

Conf: OSX with a brew Python 2.7.10 (default, Jul 13 2015, 12:05:58), and pandas==0.17.0 and matplotlib==1.5.0

Shapi
  • 5,493
  • 4
  • 28
  • 39
nuin
  • 607
  • 1
  • 6
  • 11
  • What is your linux operating system name and version, what is the python version, what is the matplotlib version and what is your pandas version? – dopstar Nov 18 '15 at 23:35
  • Perhaps try something like [this](http://stackoverflow.com/a/24502872/3581217)? I can't test it, since I don't get the same warning.. – Bart Nov 19 '15 at 15:47
  • I am on OSX with a brew Python 2.7.10 (default, Jul 13 2015, 12:05:58), and pandas==0.17.0 and matplotlib==1.5.0 – nuin Nov 19 '15 at 17:34
  • Take a look at http://stackoverflow.com/questions/16170989/matplotlib-remove-warning-about-matplotlib-use : it proposes to use `matplotlib.use(arg, warn=False, force=False)`. See http://matplotlib.org/api/matplotlib_configuration_api.html First, from matplotlib import use, then call matplotlib.use(), then from matplotlib import *. – francis Dec 24 '15 at 13:41

5 Answers5

62

You can suppress all warnings:

import warnings
warnings.filterwarnings("ignore")

import pandas
honza_p
  • 2,073
  • 1
  • 23
  • 37
Shapi
  • 5,493
  • 4
  • 28
  • 39
  • it works for me but for how long it will be there in the script.? is it ok if we upgrading to MPL3.3? – Azam Dec 15 '21 at 06:18
18

Rather than hiding everything, you can also hide specific warnings. For instance if we want to hide only matplotlib warnings:

warnings.filterwarnings( "ignore", module = "matplotlib\..*" )

The filter can be customised down to the exact message and line number of the file in which the warning originates, let's say if it's just one warning that annoys you and not matplotlib as a whole. See https://docs.python.org/3/library/warnings.html for more details.

Note: The module bit is "a regex that the module name must match". You can make it broader if needed, e.g. .*matplot.*.

Disclaimer: The above is for the OP's warning. For people with other warnings you'll need to swap the module name for the one in the particular warning you get.

c z
  • 7,726
  • 3
  • 46
  • 59
9

You can either suppress the warning messages as suggested by AndreL or you can resolve this specific issue and stop getting the warning message once and for all. If you want the latter, do the following.

Open your matplotlibrc file and search for axes.color_cycle. If you're getting the warning message it means that your matplotlibrc file should show something like this:

axes.color_cycle : b, g, r, c, m, y, k  # color cycle for plot lines

You should replace that line by this:

axes.prop_cycle : cycler('color', ['b', 'g', 'r', 'c', 'm', 'y', 'k'])

And the warning message should be gone.

mairan
  • 303
  • 5
  • 14
1

You can suppress the warning UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter. by using prop_cycle at the appropriate place.

For example, in the place you had used color_cycle:

matplotlib.rcParams['axes.color_cycle'] = ['r', 'k', 'c']

Replace it with the following:

matplotlib.rcParams['axes.prop_cycle'] = mpl.cycler(color=["r", "k", "c"]) 

For a greater glimpse, here is an example:

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

mpl.rcParams['axes.prop_cycle'] = mpl.cycler(color=["r", "k", "c"]) 

x = np.linspace(0, 20, 100)

fig, axes = plt.subplots(nrows=2)

for i in range(10):
    axes[0].plot(x, i * (x - 10)**2)

for i in range(10):
    axes[1].plot(x, i * np.cos(x))

plt.show()

enter image description here

Steffi Keran Rani J
  • 3,667
  • 4
  • 34
  • 56
1

If you are using the logging module, try this: logging.getLogger('matplotlib').setLevel(level=logging.CRITICAL)

Ying Zhang
  • 171
  • 6