如何同时绘制具有 2 个值的颜色图?
How to draw colormap with 2 values at the same time?
我想知道如何制作这种颜色图:
enter image description here
希望能画出这样的地图。我已经为每个网格设置了两个值(即 enter image description here(p,et),(R,et)),因此我需要如何将此颜色图与我的相关值一起采用。但我不知道如何制作这个色彩图。
参考资料:A. J. Teuling.A 大陆蒸发趋势的区域视角。
谢谢!
您可以按照以下方式进行操作:
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
我想知道如何制作这种颜色图: enter image description here
希望能画出这样的地图。我已经为每个网格设置了两个值(即 enter image description here(p,et),(R,et)),因此我需要如何将此颜色图与我的相关值一起采用。但我不知道如何制作这个色彩图。 参考资料:A. J. Teuling.A 大陆蒸发趋势的区域视角。 谢谢!
您可以按照以下方式进行操作:
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