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


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

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

matplotlib.figure.Figure.get_axes()方法

matplotlib庫的get_axes()方法圖形模塊用於獲取圖形中的軸列表。

用法: get_axes(self)


參數:此方法不接受任何參數。

返回:此方法返回圖中的軸列表。

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

範例1:

# Implementation of matplotlib function 
import matplotlib.pyplot as plt 
from matplotlib.tri import Triangulation 
from matplotlib.patches import Polygon 
import numpy as np 
  
  
xs = list([ 1, 2, 3, 4, 5, 6, 7, 8, 9]) 
ys = list([9, 8, 7, 6, 5, 4, 3, 2, 1]) 
          
fig = plt.figure() 
  
ax = fig.add_subplot(111) 
ax.plot(ys, xs) 
  
fig.get_axes()[0].set_ylabel("Y label") 
fig.get_axes()[0].set_xlabel("X label") 
  
  
fig.suptitle('matplotlib.figure.Figure.get_axes()\ 
function Example\n\n', fontweight ="bold") 
  
plt.show()

輸出:

範例2:

# Implementation of matplotlib function 
import matplotlib.pyplot as plt 
from matplotlib.tri import Triangulation 
from matplotlib.patches import Polygon 
import numpy as np 
  
  
xs = list([ 1, 2, 3, 4, 5, 6, 7, 8, 9]) 
ys = list([9, 8, 7, 6, 5, 4, 3, 2, 1]) 
          
fig = plt.figure() 
  
ax = fig.add_subplot(111) 
ax.bar(ys, xs, width = 0.5, align ="center") 
  
fig.get_axes()[0].set_ylabel("Number") 
fig.get_axes()[0].set_xlabel("Values") 
  
  
fig.suptitle('matplotlib.figure.Figure.get_axes()\ 
 function Example\n\n', fontweight ="bold") 
  
plt.show()

輸出:




相關用法


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