Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 442
Dasfga Avatar asked Apr 04 '18 18:04

Dasfga


People also ask

What is Matplotlib RC?

Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.pyplot.rc () function is used to the rc params.

What is the difference between Pyplot and Matplotlib?

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface.

How to group lines in Matplotlib RC?

Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.pyplot.rc () function is used to the rc params. Grouping in rc is done through the ‘group' (eg, for lines). For lines in axes the group is linewidth. The group for axes is facecolor and so on.

What is the use of RC_context in Matplotlib?

The rc_context () function in pyplot module of matplotlib library is used to return a context manager for managing rc settings. Syntax: matplotlib.pyplot.rc_context (rc=None, fname=None)


2 Answers

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 == 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
like image 64
ImportanceOfBeingErnest Avatar answered Oct 16 '22 23:10

ImportanceOfBeingErnest


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.

like image 26
sam Avatar answered Oct 16 '22 21:10

sam