Saturday, November 16, 2024
Google search engine
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 Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments