你有一個(12,3)顏色數組,而你需要一個(4, 3, 3)圖像,每個像素一個RGB顏色。 import numpy as np # type: ignoreimport matplotlib.pyplot as plt # type: ignorecolors = np.array( [ # this is the first row [ # these are the 3 pixels in the first row [0.01, 0.08, 0.01], [0.01, 0.16, 0.01], [0.01, 0.165, 0.01], ], [ [0.01, 0.3, 0.01], [0.01, 0.2, 0.01], [0.666, 0.333, 0.01], ], [ [0.01, 0.165, 0.01], [0.01, 0.3, 0.01], [0.01, 0.2, 0.01], ], # this is the fourth row [ [0.666, 0.333, 0.01], [0.01, 0.165, 0.01], [0.01, 0.3, 0.01], ], ])print(colors.shape)fig, ax = plt.subplots()ax.imshow(colors)ax.set_aspect("equal")plt.show() 根據需要在行