當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Matplotlib.figure.Figure.sca()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。 Figure模塊提供了頂層Artist,即Figure,其中包含所有繪圖元素。此模塊用於控製所有圖元的子圖和頂層容器的默認間距。

matplotlib.figure.Figure.sca()方法

matplotlib庫的sca()方法圖形模塊用於將當前軸設置為a。

用法:sca(self, a)


參數:此方法接受下麵討論的以下參數:

  • a:該參數是當前軸。

返回值:此方法返回軸。

以下示例說明了matplotlib.figure中的matplotlib.figure.Figure.sca()函數:

範例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() 

輸出:

範例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()  

輸出:





注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.figure.Figure.sca() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。