用python plt.subplots畫色塊圖


 

from PIL import Image
import matplotlib.pyplot as plt

color_map = [(220, 20, 60), (139, 0, 139), (123, 104, 238), (248, 248, 255),
                         (0, 255, 255), (0, 255, 127), (255, 255, 0), (210, 180, 140)]

# 1行8子圖
fig, axs = plt.subplots(1, len(color_map), figsize=(15, 15))

 

for i, color in enumerate(color_map):
    img = Image.new('RGB', (10, 10), color)
    ax = axs[i]
    ax.set_title(color)
  # 去掉刻度 ax.set_xticks([]) ax.set_yticks([])
  # 去掉坐標軸
  # ax.axis('off') ax.imshow(img)
plt.savefig(r'E:\colormap.png') plt.show()

 

輸出:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM