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


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

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

matplotlib.artist.Artist.draw()方法

matplotlib庫的藝術家模塊中的draw()方法用於使用給定的渲染器繪製藝術家。

用法:Artist.draw(self, renderer, \*args, \*\*kwargs)


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

  • renderer:此參數是RendererBase子類。

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

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

範例1:

# Implementation of matplotlib function 
from matplotlib.artist import Artist 
from mpl_toolkits.mplot3d import axes3d   
import matplotlib.pyplot as plt   
       
fig, ax = plt.subplots()   
       
def tellme(s):   
    ax.set_title(s, fontsize = 16)   
    fig.canvas.draw()  
    renderer = fig.canvas.renderer  
    Artist.draw(ax, renderer)  
     
tellme('matplotlib.artist.Artist.draw() function Example')  
ax.grid()  
  
plt.show()

輸出:

範例2:

# Implementation of matplotlib function 
from matplotlib.artist import Artist 
from mpl_toolkits.mplot3d import axes3d   
import matplotlib.pyplot as plt   
       
    
fig = plt.figure()   
ax = fig.add_subplot(111, projection ='3d')   
       
X, Y, Z = axes3d.get_test_data(0.1)   
ax.plot_wireframe(X, Y, Z, rstride = 5,    
                  cstride = 5)   
       
for angle in range(0, 90):   
    ax.view_init(30, angle)  
    fig.canvas.draw()  
    renderer = fig.canvas.renderer  
    Artist.draw(ax, renderer)   
    plt.pause(.001)  
    
    fig.suptitle('matplotlib.artist.Artist.draw() function Example')  
ax.grid()  
  
plt.show()

輸出:





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