租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

Matplotlib中如何设置坐标轴范围,matplotlib subtitle

发布时间:2024-05-11 18:41:49

Matplotlib中如何设置坐标轴范围

在Matplotlib中,可使用plt.xlim()plt.ylim()函数来设置x轴和y轴的范围。示例代码以下:

import matplotlib.pyplot as plt

# 创建数据
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 25, 30]

# 绘制折线图
plt.plot(x, y)

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

# 显示图形
plt.show()

在上面的示例中,plt.xlim(0, 6)设置了x轴的范围为0到6,plt.ylim(0, 35)设置了y轴的范围为0到35。您可以根据需要调剂范围的大小。