如何同时绘制带有两个值的颜色图?

时间:2019-12-09 03:07:16

标签: python colormap

我想知道如何制作这种颜色图: enter image description here

我希望画出这种地图。我已经为每个网格设置了两个值(即enter image description here(p,et),(R,et)),所以我需要如何在相关值中采用此颜色图。但是我不知道如何制作这个色彩图。 参考文献:A. J. Teuling。关于大陆蒸发趋势的区域观点。 谢谢!

1 个答案:

答案 0 :(得分:0)

您可以按照以下步骤进行操作:

import cv2
import numpy as np
def get_rgb(two_d_pixels):
    theta = np.arctan(two_d_pixels[1,:] / two_d_pixels[0,:])
    r = np.sqrt(two_d_pixels[1,:]**2 +  two_d_pixels[0,:]**2)
    hue = (theta+3.14/2) * 128./(3.14)  # 127 max for hue
    sat = (r/np.sqrt(2)) * 255 #255 max for sat
    H,W = two_d_pixels.shape[1:3]
    retval = np.zeros([H,W,3],dtype = np.uint8)
    retval[:,:,0] = hue
    retval[:,:,1] = sat
    retval[:, :, 2] = 255
    retval = cv2.cvtColor(retval,cv2.COLOR_HSV2BGR)
    return retval

two_d_image = np.mgrid[-1:1:0.1,-1:1:0.1]
rgb = get_rgb(two_d_image)
cv2.imshow('ok',rgb)
cv2.waitKey(0)

这显示了从((-1,1),(-1,1))到RGB的映射,例如here。 我使用mgrid制作了2 * X * Y张量,rho_p和rho_rg是这两个张量平面中的值。如果您需要与本白皮书完全相同的颜色图,则可以调整hue,sat的公式,请记住,arctan的范围是-pi / 2到pi / 2,r的范围是sqrt(2)到0