问题可能出在设置坐标轴范围时没有考虑数据的大小范围。解决方法是根据数据的范围设置坐标轴刻度。
示例代码:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5] y = [10, 20, 30, 40, 50]
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_xlim(1, 5)
ax.set_ylim(0, 60)
ax.set_xticks([1, 2, 3, 4, 5])
ax.set_yticks([0, 20, 40, 60])
plt.show()