首页 > 解决方案 > 如何使用 matplotlib 更改 y 轴的比例?

问题描述

我在 python 中绘制了两个数组。但是我需要每100或1000看到y轴的演变。我希望我的问题很清楚。

将 matplotlib.pyplot 导入为 plt

y= [303, 606, 1414, 2020, 2424, 2626, 2828, 2929, 3131, 3232, 3333, 8484, 9999, 11211, 12221, 13130, 13332, 14140, 16362, 19392, 20705, 21311, 25250, 27270, 28482]
x= [0,   4,   7    , 9,   11  ,  12  ,  14,  16,   17,  85,   108,  124 ,  139,  154 ,   157,   166,  199 ,  258 ,  276,   284,   338 ,  367 ,  382 ,  382 ,  392]
print (len(x))
print (len(y))
plt.plot(x,y)
f = plt.figure()
plt.show()

在此处输入图像描述

标签: pythonmatplotlib

解决方案


您可以使用 plt.yticks(np.arange(100, step=100)) 方法。np 表示 numpy 库(将 numpy 导入为 np)。您也可以使用第二个参数设置上限:plt.yticks(np.arange(100,1000,step=100))。

希望能帮助到你。


推荐阅读