Saturday, November 15, 2025
HomeLanguagesMatplotlib.pyplot.rc_context() in Python

Matplotlib.pyplot.rc_context() in Python

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. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, etc.

matplotlib.pyplot.rc_context() Function

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)

Parameters:

  • rc: This parameter is a dictionary can also be passed to the context manager.
  • fname: This parameter contains the name of file which is to be called.

Returns: This method return a context manager for managing rc settings.

Below examples illustrate the matplotlib.pyplot.rcdefaults() function in matplotlib.pyplot:

Example 1:




# implementation of the matplotlib function
import matplotlib.pyplot as plt
import numpy as np
  
  
np.random.seed(19680801)
  
dots = np.arange(20)
x, y = np.meshgrid(dots, dots)
data = [x.ravel(), y.ravel()]
  
with plt.rc_context({'axes.xmargin': .2
                     'axes.ymargin': .4}):
    plt.scatter(*data, c = data[1])
      
plt.grid(True)
  
plt.title('matplotlib.pyplot.rc_context()\
Example')
plt.show()


Output:

Example 2:




# implementation of the matplotlib function
import matplotlib.pyplot as plt
import numpy as np
  
  
np.random.seed(19680801)
  
fig, ax = plt.subplots()
dots = np.arange(100)
x, y = np.meshgrid(dots, dots)
  
data = [x.ravel(), y.ravel()]
ax.scatter(*data, c = data[1])
  
with plt.rc_context({'axes.autolimit_mode': 'round_numbers',
                     'axes.xmargin': .8,
                     'axes.ymargin': .8}):
      
    fig, ax = plt.subplots()
    ax.scatter(*data, c = data[1])
      
plt.grid(True)
  
plt.title('matplotlib.pyplot.rc_context() Example')
plt.show()


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7143 POSTS0 COMMENTS
Thapelo Manthata
6838 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS