如果你有y数据
y = [0., 0.5, 1., 1.5, 2., 2.5]
您可以使用此数据的最大值和最小值来创建此范围内的自然数列表。例如,
import mathprint range(math.floor(min(y)), math.ceil(max(y))+1)
产量
[0, 1, 2, 3]
然后,您可以使用matplotlib.pyplot.yticks设置y刻度位置(和标签):
yint = range(min(y), math.ceil(max(y))+1)matplotlib.pyplot.yticks(yint)



