You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使Matplotlib的Y轴从0起始?像素索引绘图问题解决

问题:让像素索引绘图的Y轴从0开始

我尝试用像素索引技术绘制图像,仅显示白色像素,代码如下:

img = cv2.imread('img.png')
img = cv2.resize(img, (180, 119))
arr0 = np.array(img)

height, width, _ = arr0.shape

x = range(width)
y = [height - np.argwhere(arr0[:, i, 0]==255).mean() for i in x]

plt.plot(y)
plt.show()

绘图结果的Y轴起始值为63,但我希望Y轴从0开始。尝试过使用np.tan(height),结果不符合预期,求解决方法?


已解决:调整Y轴起始值的方法

更新!我已经找到让Y轴从0开始的方法:

img = cv2.imread('img.png')
img = cv2.resize(img, (180, 119))
arr0 = np.array(img)

height, width, _ = arr0.shape

x = range(width)
y = [63.5 - np.argwhere(arr0[:, i, 0]==255).mean() for i in x] # 只需把原来的height换成起始值63.5

plt.plot(y)
plt.show()

谢谢大家!


内容的提问来源于stack exchange,提问作者noobstacker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 20:27:38