我有一堆 288 x 288
像素的 7 张图像,我已将其转换为 3d NumPy 数组
newarray.shape = (288, 288, 7)
我想从 7 个图像中的每一个中绘制特定的像素值,并将其绘制为图表,其中 y 轴显示像素值,x 轴显示图像编号。
最佳答案
from matplotlib import pyplot as plt
import numpy as np
# NumPy array storing images
images = np.random.randint(0, 255, (288, 288, 7), np.uint8)
# Get pixel values across all images of pixel of interest
x, y = (8, 3)
pixels = images[y, x, :]
# Plot
plt.plot(np.arange(images.shape[2]), pixels)
plt.ylim(0, 255)
plt.title('Pixel values for x=' + str(x) + ', y=' + str(y))
plt.tight_layout()
plt.show()
输出:
希望有帮助!
----------------------------------------
System information
----------------------------------------
Platform: Windows-10-10.0.16299-SP0
Python: 3.8.1
Matplotlib: 3.2.0rc3
NumPy: 1.18.1
----------------------------------------
关于python - 如何从 3d NumPy 数组绘制单个像素值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60311884/