How to suppress matplotlib warning?

前端 未结 5 1960
借酒劲吻你
借酒劲吻你 2020-12-01 14:22

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

/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py:8         


        
5条回答
  •  粉色の甜心
    2020-12-01 14:49

    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()
    

提交回复
热议问题