如何使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
相关产品推荐
相关产品推荐

