温馨提示×

python怎么设置坐标轴范围

小亿
95
2024-05-25 09:58:11
栏目: 编程语言

在Python中,可以使用Matplotlib库来设置坐标轴的范围。下面是一个简单的示例代码来设置x和y坐标轴的范围:

import matplotlib.pyplot as plt

# 创建数据
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]

# 创建图形
plt.plot(x, y)

# 设置x和y坐标轴的范围
plt.xlim(0, 6) # 设置x轴范围为0到6
plt.ylim(0, 30) # 设置y轴范围为0到30

# 显示图形
plt.show()

在上面的代码中,plt.xlim()plt.ylim()函数分别用来设置x和y坐标轴的范围。你可以根据需要调整范围来显示你感兴趣的数据部分。

0