python-3.x - 如何在同一图中绘制水平图和垂直图?
问题描述
我想使用 matplotlib 在实际图像顶部用图形可视化二值化图像文件中黑色像素的数量。这是图像:
我设法计算了垂直(x_counts
)和水平(y_counts
)的像素。我仍然想不通的是如何转置 的值y_counts
,以便 y_counts-graph 与x_counts
.
这是我的代码:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img_file = "sample.png"
img = mpimg.imread(img_file)
#Count black pixels on x- and y-axis
x_counts = np.sum(img==0, axis=0)
y_counts = np.sum(np.transpose(img)==0, axis=0)
print(y_counts)
input()
#Show image
plt.imshow(img)
#Show number of pixels
plt.plot(x_counts)
plt.plot(y_counts) ### Problem: Graph as to be transposed
plt.show()
我得到的是:
但我想将橙色图形逆时针旋转 90°。
任何帮助将不胜感激!
解决方案
推荐阅读
- h2db - 如何更改 H2DB 控制台应用程序的默认端口号(8082)?
- javascript - 删除数组对象也在删除引用
- java - 代码运行但它没有给我正确的输出
- python - 如何从 C/C++ 调用用 numba 编写的函数
- django - 如何在模型的 save 方法中访问 ManyToManyField?
- python - Windows批处理文件运行Python脚本来检查安装的包版本?
- coldfusion - GSuite Admin API 不再适用于用户更新
- java - 如何在 .txt 文件上写入内容?
- angular - Angular 8 HttpClient 发布请求内容类型崩溃
- c++ - 如何打印 MergeSort 的所有中间步骤?