xlim and ylim of python data visualization matplotlib

xlim() and ylim() – set the numerical display range

No video link yet

Function format:

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

Parameter Description:

  • xmin: the lower limit of the display on the x-axis
  • xmax: display upper limit on the x-axis

code:

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

Guess you like

Origin blog.csdn.net/wudechun/article/details/105896708