影像矩陣僅包含0,1,2,3值。您能否建議如何:
轉換:
[(0, white color),(1, red color),(2, green color),(3, blue color)]使用 matplotlib 顯示時。垂直對齊影像底部。
代碼:
from matplotlib import pyplot as plt
import numpy as np
img1 = np.random.randint(0, 3, (1, 4)).tolist()
img2 = np.random.randint(0, 3, (2, 4)).tolist()
img3 = np.random.randint(0, 3, (4, 4)).tolist()
fig = plt.figure()
fig.set_size_inches(10, 5)
ax0 = plt.subplot(1, 3, 1)
ax0.pcolor(img1, edgecolors='k', linewidths=2, vmin=0, vmax=4, cmap='gray')
ax0.set_aspect('equal')
ax0.axis("off")
plt.gca().invert_yaxis()
ax1 = plt.subplot(1, 3, 2)
ax1.pcolor(img2, edgecolors='k', linewidths=2, vmin=0, vmax=4, cmap='gray')
ax1.set_aspect('equal')
ax1.axis("off")
plt.gca().invert_yaxis()
ax2 = plt.subplot(1, 3, 3)
ax2.pcolor(img3, edgecolors='k', linewidths=2, vmin=0, vmax=4, cmap='gray')
ax2.set_aspect('equal')
ax2.axis("off")
plt.gca().invert_yaxis()
plt.show()

uj5u.com熱心網友回復:
您可以為此使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/424628.html
標籤:Python matplotlib
上一篇:擲骰子的概率
