python - 如何使用 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()
解决方案
您可以使用 plt.yticks(np.arange(100, step=100)) 方法。np 表示 numpy 库(将 numpy 导入为 np)。您也可以使用第二个参数设置上限:plt.yticks(np.arange(100,1000,step=100))。
希望能帮助到你。
推荐阅读
- excel - ActiveX 文本框在单击设计视图之前不会更新
- reporting-services - SSRS 报告:要导出到 1 张 PowerPoint 幻灯片的多个图表
- c - tmpname 函数在 Sun Solaris 环境中将临时文件写入何处?
- python - matplotlib 没有 pyplot 的全局状态
- java - Selenium java如何从第二个引号“”中的元素获取文本
- php - PHP 动态定义的变量(在有两个条件的 while 循环中使用)
- c# - 为什么在 datagridview 的列中按日期过滤时会出错?'System.NotSupportedException' DataGridViewAutoFilter.dll
- javascript - 如何在不使用 jquery 的情况下在纯 JavaScript 中使用对象的函数?
- html - 在移动浏览器、Chrome 和 Safari 上不工作的标题标签隐藏溢出。仅适用于桌面浏览器
- powershell - 从 powershell 运行的 jMeter 错误。错误级别=-1073741819