matlab waitfor函数,Python Matplotlib.pyplot.waitforbuttonpress()用法及代码示例

本文介绍了Python的Matplotlib库中的Pyplot模块以及waitforbuttonpress()函数。waitforbuttonpress()方法用于在图形界面中等待用户的交互,例如点击,可以阻止程序执行直到用户按下按钮或达到指定的超时时间。通过示例代码展示了如何在图形界面中应用此方法,等待用户交互并获取结果。
摘要由CSDN通过智能技术生成

Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,该模块提供了MATLAB-like接口。可在Pyplot中使用的各种图线图,轮廓图,直方图,散点图,3D图等。

matplotlib.pyplot.waitforbuttonpress()方法

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

用法:matplotlib.pyplot.waitforbuttonpress(timeout=- 1)

参数:此方法接受下面讨论的以下参数:

timeout:此参数是超时值。

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

以下示例说明了matplotlib.pyplot中的matplotlib.pyplot.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.pyplot.waitforbuttonpress()

function Example\n\n""", fontweight ="bold")

w = plt.waitforbuttonpress()

print("Result after", ite, "click", w)

plt.show()

输出:

a1fe02917ad107706c89dfb9a67c48aa.png

b5d38fdb61c492bfbfb6338441ebbf7a.png

范例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)

plt.clf()

ax.axis([-1., 1., -1., 1.])

plt.setp(plt.gca(), autoscale_on = False)

tellme("""matplotlib.pyplot.waitforbuttonpress()

function Example\n\n""")

w = plt.waitforbuttonpress()

print("Result after click:", w)

plt.show()

输出:

8217f1a1b81a8e36146c68fc21fbc34c.png

c11f1232a611a3600d8b925e0ea3bbc5.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值