HomeLanguagesMatplotlib.figure.Figure.sca() in Python

Matplotlib.figure.Figure.sca() in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements.

matplotlib.figure.Figure.sca() method

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

Syntax: 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.figure.Figure.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)
  
fig.sca(ax[0])
plt.plot(x, y1)
  
fig.sca(ax[1])
plt.plot(x, y2)
  
fig.suptitle("""matplotlib.figure.Figure.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):
    fig.sca(axes[i])
    axes[i].text(0.5, 0.5, i + 1)
      
fig.suptitle("""matplotlib.figure.Figure.sca()
function Example\n\n""", fontweight ="bold") 
    
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
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS