Python中的 Matplotlib.axes.Axes.drag_pan()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.drag_pan()函数
matplotlib 库的 axes 模块中的Axes.drag_pan()函数在平移操作期间鼠标移动时被调用。
Syntax: Axes.drag_pan(self, button, key, x, y)
Parameters: This method accept the following parameters that are described below:
- x, y: These parameter are the mouse coordinates in display coords.
- key : This parameter is the “shift” key.
- button: This parameter is the mouse button number:
- 1: LEFT
- 2: MIDDLE
- 3: RIGHT
Returns: This methods does not return any value.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.drag_pan()函数:
示例 1:
Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(10**7)
data = np.random.normal(0, 5, 100)
fig, ax1 = plt.subplots()
val = ax1.violinplot(data)
ax1.start_pan(1, 0, 3)
ax1.drag_pan(1, "shift", 0, 0.6)
ax1.set_title('matplotlib.axes.Axes.drag_pan() Example')
plt.show()
Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
geeks = np.array([24.40, 110.25, 20.05,
22.00, 61.90, 7.80,
15.00, 22.80, 34.90,
57.30])
fig, ax = plt.subplots()
ax.acorr(geeks, maxlags = 9)
ax.set_ylabel('Y-axis')
ax.start_pan(0, 0.6, 1)
ax.drag_pan(1, "shift", 0, 0.6)
ax.set_title('matplotlib.axes.Axes.drag_pan() Example')
plt.show()
输出:
示例 2:
Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
geeks = np.array([24.40, 110.25, 20.05,
22.00, 61.90, 7.80,
15.00, 22.80, 34.90,
57.30])
fig, ax = plt.subplots()
ax.acorr(geeks, maxlags = 9)
ax.set_ylabel('Y-axis')
ax.start_pan(0, 0.6, 1)
ax.drag_pan(1, "shift", 0, 0.6)
ax.set_title('matplotlib.axes.Axes.drag_pan() Example')
plt.show()
输出: