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


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

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

matplotlib.figure.Figure.waitforbuttonpress()方法

matplotlib庫的waitforbuttonpress()方法圖形模塊用於阻止與圖形交互的調用。

用法: waitforbuttonpress(self, timeout=-1)


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

  • timeout:此參數是超時值。

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

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

範例1:

# Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
  
for ite in range(2):
    x = np.linspace(-2, 6, 100) 
    y = (ite + 1)*x 
  
    fig = plt.figure() 
    ax = fig.subplots() 
    ax.plot(x, y, '-b') 
  
    fig.suptitle("""matplotlib.figure.Figure.waitforbuttonpress() 
    function Example\n\n""", fontweight ="bold") 
  
    w = fig.waitforbuttonpress() 
    print("Result after", ite, "click", w) 
  
    fig.show()

輸出:

python-matplotlib-waitforbuttonpress-1

python-matplotlib-wairforbuttonpress-2

範例2:

# Implementation of matplotlib function 
import numpy as np 
import matplotlib.cm as cm 
import matplotlib.mlab as mlab 
import matplotlib.pyplot as plt 
  
fig = plt.figure() 
ax = fig.subplots() 
  
def tellme(s):
      
    fig.suptitle(s, fontweight ="bold") 
    fig.canvas.draw() 
    renderer = fig.canvas.renderer 
    fig.draw(renderer) 
  
fig.clf() 
ax.axis([-1., 1., -1., 1.]) 
plt.setp(plt.gca(), autoscale_on = False) 
  
tellme("""matplotlib.figure.Figure.waitforbuttonpress() 
    function Example\n\n""") 
  
w = fig.waitforbuttonpress() 
print("Result after click:", w) 
fig.show()

輸出:

python-matplotlib-waitforbuttonpress-3

python-matplotlib-waitforbuttonpress-4




相關用法


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