How to recover matplotlib defaults after setting stylesheet

前端 未结 3 1355
遥遥无期
遥遥无期 2020-12-04 13:20

In an ipython notebook, I used a matplotlib stylesheet to change the look of my plots using

from matplotlib.pyplot import *
%matplotlib inline
style.use(\'g         


        
3条回答
  •  失恋的感觉
    2020-12-04 13:51

    You should be able to set it back to default by:

    import matplotlib as mpl
    mpl.rcParams.update(mpl.rcParamsDefault)
    

    In ipython, things are a little different, especially with inline backend:

    In [1]:
    
    %matplotlib inline
    In [2]:
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    In [3]:
    
    inline_rc = dict(mpl.rcParams)
    In [4]:
    
    plt.plot(range(10))
    Out[4]:
    []
    

    enter image description here

    In [5]:
    
    mpl.rcParams.update(mpl.rcParamsDefault)
    plt.plot(range(10))
    Out[5]:
    []
    

    enter image description here

    In [6]:
    
    mpl.rcParams.update(inline_rc)
    plt.plot(range(10))
    Out[6]:
    [] 
    

    enter image description here

    Basically, %matplotlib inline uses its own rcParams. You can grab that from the source, but the arguably easier way is probably just save the rcParams as inline_rc after %matplotlib inline cell magic in this example, and reuse that later.

提交回复
热议问题