matlab ylim是什么,Python Matplotlib.pyplot.ylim()用法及代码示例

Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,该模块提供了MATLAB-like接口。

matplotlib.pyplot.ylim()功能

matplotlib库的pyplot模块中的ylim()函数用于获取或设置当前轴的y-limits。

用法: matplotlib.pyplot.ylim(*args, **kwargs)

参数:此方法接受以下描述的参数:

bottom:此参数用于将ylim设置为底部。

top:此参数用于将ylim设置为top。

**kwargs:此参数是文本属性,用于控制标签的外观。

返回值:这将返回以下内容:

底部,顶部:这将返回新的y轴限制的元组。

以下示例说明了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()

输出:

7625485bb602fce767ace61dc3c2ad4e.png

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

输出:

7bca8de4e355d5933f8ae7dce32d4ed9.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值