【问题标题】:How to plot a 2D RGB colormap from array?如何从数组中绘制 2D RGB 颜色图?
【发布时间】:2021-10-21 23:48:18
【问题描述】:

我正在尝试绘制 2D 颜色图。 我会想象这样的事情:

grid = np.ndarray([2,2])
grid[0,0] = [35,74,3]
grid[0,1] = [146,252,7]
grid[1,0] = [215,84,14]
grid[1,1] = [16,62,8]

plotter.map(grid)

什么库支持这个?

【问题讨论】:

  • 你可以使用matplotlibsimshow()。它支持直接绘制 numpy 数组,并且可以指定颜色图。网上也有很多关于如何使用它的教程。

标签: python colors grid colormap


【解决方案1】:
from PIL import Image
import random
import numpy as np

steps = 100

grid = np.ndarray([steps,steps,3])

for step_search_depth in range(steps):
    for step_simulated_games_per_state in range(steps):
        colour = random.randint(0,200)
        grid[step_search_depth, step_simulated_games_per_state] = (colour,colour,colour)

Image.fromarray(grid, 'RGB').show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-20
    • 2013-06-19
    • 2017-06-02
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多