📌  相关文章
📜  Python中的 Matplotlib.figure.Figure.waitforbuttonpress()

📅  最后修改于: 2022-05-13 01:54:43.321000             🧑  作者: Mango

Python中的 Matplotlib.figure.Figure.waitforbuttonpress()

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 figure 模块提供了顶级 Artist,即 Figure,其中包含所有绘图元素。该模块用于控制所有绘图元素的子图和顶级容器的默认间距。

matplotlib.figure.Figure.waitforbuttonpress() 方法

matplotlib 库的waitforbuttonpress() 方法图形模块用于阻塞调用与图形交互。

下面的示例说明了 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