Matplotlib ax.set_xlim() 无效示例:设置范围超出数据范围
很抱歉,我的回答有误。确实可以使用ax.set_xlim()来设置x轴的范围。以下是一个ax.set_xlim()没有实际效果的例子:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
fig, ax = plt.subplots()
ax.plot(x, y)
# 设置x轴范围为[0, 6]
ax.set_xlim(0, 6)
plt.show()
在这个例子中,我们设置x轴的范围为[0, 6],但是实际上我们的数据点的x轴范围是[1, 5],因此ax.set_xlim()没有实际效果。
原文地址: https://www.cveoy.top/t/topic/jYJP 著作权归作者所有。请勿转载和采集!