Python中的 Matplotlib.axis.Axis.zoom()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Axis.zoom()函数
matplotlib 库的 axis 模块中的Axis.zoom()函数用于放大或缩小 axis 。
Syntax: Axis.zoom(self, direction)
Parameters: This method accepts the following parameters.
- direction: This parameter is the value to zoom in (direction > 0) or zoom out (direction <= 0).
Return value: This method does not return any value.
下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.zoom()函数:
示例 1:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
ax.xaxis.zoom(3)
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.zoom()
function Example\n""", fontweight ="bold")
plt.show()
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
fig, ax1 = plt.subplots()
plt.subplots_adjust(bottom = 0.25)
t = np.arange(0.0, 1.0, 0.001)
a0 = 5
f0 = 3
delta_f = 5.0
s = a0 * np.sin(2 * np.pi * f0 * t)
ax1.plot(t, s, lw = 2, color = 'green')
ax1.xaxis.zoom(-2)
ax1.grid()
fig.suptitle("""matplotlib.axis.Axis.zoom()
function Example\n""", fontweight ="bold")
plt.show()
输出:
示例 2:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
fig, ax1 = plt.subplots()
plt.subplots_adjust(bottom = 0.25)
t = np.arange(0.0, 1.0, 0.001)
a0 = 5
f0 = 3
delta_f = 5.0
s = a0 * np.sin(2 * np.pi * f0 * t)
ax1.plot(t, s, lw = 2, color = 'green')
ax1.xaxis.zoom(-2)
ax1.grid()
fig.suptitle("""matplotlib.axis.Axis.zoom()
function Example\n""", fontweight ="bold")
plt.show()
输出: