缩放y轴并在Matplotlib图中设置ytick标签

我想用一个例子来解释我的查询,这是一个示例代码片段

x = [i for i in range(1, 129)]
y = [i**2 for i in x]
plt.plot(x, y)
plt.show()

输出:

enter image description here

I want the scale the y axis so that it shows only three equally spaced ytick labels: [0, 5000, 15000], for this I used matplotlib's set_yticks functionality:

x = [i for i in range(1, 129)]
y = [i**2 for i in x]

plt.plot(x, y)
plt.yticks([0, 7500, 15000], [0, 5000, 15000])
plt.show()

输出:

enter image description here

当ytick标签如我所愿显示时,曲线没有改变,我希望曲线会根据新的ytick标签自行缩放。我不想在情节中更改xtick标签。有什么办法吗?

评论
  • son
    son 回复

    你有没有尝试过

    plt.xlim(number)
    plt.ylim(number)