使用matplotlib在绘图中设置轴的比例

时间:2015-06-27 15:45:43

标签: python matplotlib

我无法缩放y轴。我的代码如下:

{{1}}

y轴的比例为5.我试图将其设为1。 The output snapshot

1 个答案:

答案 0 :(得分:1)

您可以使用set_yticks这样做:

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
sample = 20
x=np.arange(sample)
y=10*np.sin(2*np.pi*x/20)

ax.plot(x,y)
ax.set_yticks(np.arange(min(y), max(y)+1, 1.0)) # setting the ticks
ax.set_xlabel('x')
ax.set_ylabel('y')
fig.show()

生成此图像,其中y-axis的比例为1.

enter image description here

相关问题