matplotlib python中的自定义Yaxis图

问题描述 投票:0回答:2

让我们说如果我有Height = [3, 12, 5, 18, 45]并绘制我的图形,那么yaxis将有一个从0开始到45的间隔为5,这意味着0,5,10,15,20等等,最多45个。有没有办法定义间隔间隙(或步长)。例如,我希望yaxis对于相同的数据集为0,15,30,45。

python matplotlib
2个回答
1
投票
import matplotlib.pyplot as plt
import numpy as np

plt.plot([3, 12, 5, 18, 45])
plt.yticks(np.arange(0,45+1,15))
plt.show()

1
投票

这应该工作

matplotlib.pyplot.yticks(np.arange(start, stop+1, step))

© www.soinside.com 2019 - 2024. All rights reserved.