這是可能的,如果你有一個調色板根據三個函數定義,或者如果你有一個數據文件保存調色板值。
考慮一下,你有一個映射函數map(x)
(即你的自定義函數),它從[0:1] -> [0:1]
映射並拉伸/縮小灰度範圍。然後,你可以使用:
red(x) = ...
green(x) = ...
blue(x) = ...
map(x) = ...
set palette functions red(map(gray)), green(map(gray)), blue(map(gray))
並據此對文件:
map(x) = ...
set palette file 'palette.dat' using (map($1)):2:3:4
在您的情況,您可以:
- 像你想要的(例如用
set palette defined ...
) 定義調色板
- 將調色板寫入外部數據文件。這寫入了一個數據集'紅',一個'綠',一個'藍'和一個NTSC灰度值。
重新排列數據文件以便對set palette file
有用。這裏我用下面的python腳本palette.py
:
import numpy as np
import sys
A = np.loadtxt(sys.stdin, usecols=(0,1))
np.savetxt(sys.stdout, A.reshape(256,8, order='F')[:,(0,4,5,6,7)], fmt='%.3f')
定義一個適當的map(x)
功能。
下面是腳本:
# 1.
set palette defined (1 "#B0E2FF", 2 "#87CEFA", 3 "#7EC0EE", 4 "#4F94CD", 5 "#4E78A0", 6 "#104E8B", 7 "#1B3F8B", 8 "#162252")
# 2.
set terminal push
set terminal unknown
set table 'palette.tmp'
test palette
unset table
set terminal pop
# 3.
system('python palette.py <palette.tmp> palette.dat')
# 4.
map(x) = (-0.5+(2*(x-0.5))**3 + x)/3 + 0.5
set palette file 'palette.dat' using (map($1)):2:3:4
test palette