python数据可视化matplotlib之xlim与ylim

xlim()与ylim()–设置数值显示范围

视频链接暂无

函数格式:

plt.xlim(xmin,xmax)
plt.ylim(ymin,ymax)

参数说明:

  • xmin:x轴上的显示下限
  • xmax:x轴上的显示上限

代码:

import matplotlib.pyplot as plt
import numpy as np

# 准备数据
# x与y中的100都是指的数据的个数,需要一致
x = np.linspace(0,10,100)
y = np.random.rand(100)

# 画图
plt.scatter(x,y,label="scatter")
# 设置x轴的显示范围
plt.xlim(0,5)
# 设置y轴的显示范围
plt.ylim(0,0.5)

# 结束
plt.legend()
plt.show()

猜你喜欢

转载自blog.csdn.net/wudechun/article/details/105896708