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


Python Matplotlib.artist.Artist.update()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。 Artist類包含用於呈現到FigureCanvas中的對象的Abstract基類。圖中所有可見元素都是Artist的子類。

matplotlib.artist.Artist.update()方法

matplotlib庫的藝術家模塊中的update()方法用於從字典道具中更新該藝術家的屬性。

用法:Artist.update(self, props)


參數:此方法接受以下參數。

  • props:此參數是屬性的字典。

返回值:此方法不返回任何值。

以下示例說明了matplotlib中的matplotlib.artist.Artist.update()函數:

範例1:

# Implementation of matplotlib function 
from matplotlib.artist import Artist 
import matplotlib.pyplot as plt  
import numpy as np  
  
          
np.random.seed(10**7)  
geeks = np.random.randn(100)  
     
fig, ax = plt.subplots()  
ax.acorr(geeks, usevlines = True,  
         normed = True,  
         maxlags = 80, lw = 3)  
    
ax.grid(True)  
    
prop = {'xticks':np.array([-10., -5., 
                            0., 5., 10.]),  
        'yticks':np.array([-0.2,  0.2,  
                            0.6, 1., 1.4]),  
        'ylabel':None, 'xlabel':None}  
    
Artist.update(ax, prop)  
           
fig.suptitle('matplotlib.artist.Artist.update()\ 
 function Example', fontweight ="bold")  
  
plt.show()

輸出:

範例2:

# Implementation of matplotlib function 
from matplotlib.artist import Artist 
import numpy as np   
import matplotlib.pyplot as plt   
    
    
xx = np.random.rand(16, 30)   
       
fig, ax = plt.subplots()   
       
m = ax.pcolor(xx)   
m.set_zorder(-20)  
prop = {'autoscalex_on':False} 
  
Artist.update(ax, prop)  
           
fig.suptitle('matplotlib.artist.Artist.update() \ 
function Example', fontweight ="bold")  
  
plt.show()

輸出:





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