Python中的 Matplotlib.pyplot.ginput()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是 Matplotlib 模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。在 Pyplot 中可以使用各种图,包括线图、等高线图、直方图、散点图、3D 图等。
matplotlib.pyplot.table()函数
matplotlib 库的 ginput() 方法pyplot 模块用于阻止调用以与图形交互。
Syntax: matplotlib.pyplot.ginput(n=1, timeout=30, show_clicks=True, mouse_add=1, mouse_pop=3, mouse_stop=2)
Parameters: This method accept the following parameters that are described below:
- n : This parameter is the number of mouse clicks to accumulate.
- timeout : This parameter is the number of seconds to wait before timing out.
- show_clicks : This parameter is used to show a red cross at the location of each click.
- mouse_add : This parameter is the Mouse button used to add points.
- mouse_pop : This parameter is the Mouse button used to remove the most recently added point.
- mouse_stop : This parameter is the Mouse button used to stop input.
Returns: This method return the list of the clicked (x, y) coordinates.
下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.ginput()函数:
示例 1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(10)
plt.plot(t, np.sin(t))
plt.title('matplotlib.pyplot.ginput()\
function Example', fontweight ="bold")
print("After 3 clicks :")
x = plt.ginput(3)
print(x)
plt.show()
输出:
After 3 clicks :
[(4.460080645161289, 0.5915838985273842),
(4.460080645161289, 0.5915838985273842),
(4.460080645161289, 0.5915838985273842)]
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(10**7)
x1 = np.random.rand(103, 53)
plt.title('matplotlib.pyplot.ginput() function\
Example', fontweight ="bold")
print("After 2 clicks :")
plt.imshow(x1)
x = plt.ginput(2)
print(x)
plt.show()
输出:
After 2 clicks :
[(8.443181818181813, 38.90530303030302),
(8.443181818181813, 38.90530303030302)]