Python中的 Matplotlib.pyplot.ylim()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。
matplotlib.pyplot.ylim()函数
matplotlib 库的 pyplot 模块中的ylim()函数用于获取或设置当前轴的 y 限制。
Syntax: matplotlib.pyplot.ylim(*args, **kwargs)
Parameters: This method accept the following parameters that are described below:
- bottom: This parameter is used to set the ylim to bottom.
- top: This parameter is used to set the ylim to top.
- **kwargs: This parameter is Text properties that is used to control the appearance of the labels.
Returns: This returns the following:
- bottom, top :This returns the tuple of the new y-axis limits.
下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.ylim()函数:
示例 #1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
ax = plt.subplot(111)
t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2 * np.pi * t)
line, = plt.plot(t, s, lw = 2)
plt.annotate('local max', xy =(2, 1),
xytext =(3, 1.5),
arrowprops = dict(facecolor ='black',
shrink = 0.05), )
plt.ylim(-2, 2)
plt.title(" matplotlib.pyplot.ylim() Example")
plt.show()
输出:
示例 #2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(9680801)
mu, sigma = 50, 13
x = mu + sigma * np.random.randn(10000)
# the histogram of the data
n, bins, patches = plt.hist(x, 50,
density = True,
facecolor ='g',
alpha = 0.75)
plt.xlabel('No of Users in K')
plt.title('Histogram of IQ')
plt.text(50, .035, r'$\mu = 50,\
\ \sigma = 13$')
plt.xlim(-10, 110)
plt.ylim(0, 0.04)
plt.grid(True)
plt.title(" matplotlib.pyplot.ylim() Example")
plt.show()
输出: