10

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?

2 Answers 2

10

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
Sign up to request clarification or add additional context in comments.

Comments

4

In this particular case, matplotlib/pyplot.py imports rcParams from matplotlib.

So this: from matplotlib import rcParams, rcParamsDefault, get_backend imports from this.

I only looked for that specific example, but in this case they refer to the same code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.