Wednesday, July 3, 2024
HomeLanguagesPythonMatplotlib.pyplot.sca() in Python

Matplotlib.pyplot.sca() 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.sca() method

The sca() method pyplot module of matplotlib library is used to set the current axes to be a.

Syntax: matplotlib.pyplot.sca(self, a)

Parameters: This method accept the following parameters that are discussed below:

  • a:This parameter is the current axes.

Returns: This method returns the axes.

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

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
from scipy import sin, cos
  
  
fig, ax = plt.subplots(2, 1)
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  
y1 = sin(x)
y2 = cos(x)
  
plt.sca(ax[0])
plt.plot(x, y1)
  
plt.sca(ax[1])
plt.plot(x, y2)
  
fig.suptitle("""matplotlib.pyplot.sca()
function Example\n\n""", fontweight ="bold") 
    
plt.show() 


Output:

Example 2:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
   
  
fig, axes = plt.subplots(2, 2
axes = axes.flatten() 
  
for i in range(4):
    plt.sca(axes[i])
    axes[i].text(0.5, 0.5, i + 1)
      
fig.suptitle("""matplotlib.pyplot.sca()
function Example\n\n""", fontweight ="bold") 
    
plt.show()  


Output:

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments