pythonmatplotlib

What's the difference between matplotlib.rc and matplotlib.pyplot.rc?


I understand that in matplotlib, you can use rc or rcParams to custom the style of your plotting. However, it seems that these functions exist in two levels, like matplotlib.rc vs matplotlib.pyplot.rc, or matplotlib.rcParams vs matplotlib.pyplot.rcParams. Are these pairs equivalent functions in practice?


Solution

  • The answer by sam is of course correct. They are all the same object, which is available from different namespaces.

    When in doubt in such a case, just test for yourself.

    import matplotlib
    import matplotlib.pyplot as plt
    
    print(matplotlib.rcParams is plt.rcParams)
    
    # This prints True
    

    They are not only the same at initialization, but they are really the same object, hence if you change the one, you change the other (because there is no "other")

    matplotlib.rcParams["xtick.color"] = "red"
    print(plt.rcParams["xtick.color"])
    
    # This prints red