How to set the range of the y-axis in Python?
You can set the range of the y-axis using the ylim() function in the matplotlib library. An example is shown below:
import matplotlib.pyplot as plt
# 创建一个示例数据
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 25, 30]
plt.plot(x, y)
# 设置y轴范围为0到40
plt.ylim(0, 40)
plt.show()
In the example above, we used plt.ylim(0, 40) to set the y-axis range from 0 to 40. You can adjust the y-axis range to suit your own data and needs.