투명도를 값에 의존하는 방법을 완전히 이해하지 못 했으므로 일반적인 대답을 제공합니다. 여기서 투명성 기능을 대신 사용할 수 있습니다.
transparency for line colors을 지정할 수 있지만 팔레트를 사용할 때는 불가능합니다. 원하는 것을 달성하는 가장 간단한 방법입니다. gnuplot을 사용하는 것만으로도 가장 멀리 갈 수있는 방법은 다음 스크립트에서와 같이 색상을 투명하게 보이게하는 것입니다. 여기서 in.data는 샘플 데이터가있는 파일입니다.
#!/usr/bin/env gnuplot
set term pngcairo
in_data = "in.data"
set out "out.png"
# function to combine color and alpha channels with white background
# 0: no transparency, 1: fully transparent
make_transparent(x1, t) = (1-t)*x1 + t
# a function to decide transparency
# the input and output must be in range of [0,1]
#get_transparency(x1) = 0 # no transparency
#get_transparency(x1) = 1 # fully transparent
get_transparency(x1) = 1 - x1 # smaller values are more transparent
# convenience function to truncate values
minval(x1, x2) = x1<x2?x1:x2
maxval(x1, x2) = x1>x2?x1:x2
truncval(x1, xmin, xmax) = maxval(minval(x1, xmax), xmin)
trunc(x1) = truncval(x1, 0, 1)
# the default palette consists of rgbfunctions 7,5,15
# we redefine their transparency enabled versions here
# the input and output must be in range of [0,1]
# see other formulae with "show palette rgbformulae" command in gnuplot
f7(x1) = make_transparent(sqrt(x1) , get_transparency(x1))
f5(x1) = make_transparent(x1**3 , get_transparency(x1))
f15(x1) = make_transparent(trunc(sin(2*pi*x1)), get_transparency(x1))
set palette model RGB functions f7(gray),f5(gray),f15(gray)
splot in_data palette
이 스크립트는 배경은 흰색이지만 다른 단색 배경에도 적용 할 수 있다고 가정합니다. 그러나 포인트가 겹쳐지기 시작하면 붕괴됩니다.
실제 투명도를 얻으려면 각 데이터 요소를 별도의 선으로 표시하고 별개의 선 색상을 지정해야합니다. 이것은 다음 bash 스크립트에서와 같이 데이터를 사전 처리하여 얻을 수 있습니다.
#!/usr/bin/env bash
set -eu
in_data="in.data"
out_png="out.png"
pi=3.141592653589793
# function to convert data value into rgba value
function value2rgba()
{
# arguments to function
local val="${1}"
local min="${2}"
local max="${3}"
# normalized value
local nval=$(bc -l <<< "(${val}-${min})/(${max}-${min})")
#### alpha channel value ####
local alpha="$(bc -l <<< "255 * (1-${nval})")"
# round to decimal
alpha=$(printf "%0.f" "${alpha}")
#### red channel value ####
# rgbformulae 7 in gnuplot
local red="$(bc -l <<< "255 * sqrt(${nval})")"
# round to decimal
red=$(printf "%0.f" "${red}")
#### green channel value ####
# rgbformulae 5 in gnuplot
local red="$(bc -l <<< "255 * sqrt(${nval})")"
local green="$(bc -l <<< "255 * ${nval}^3")"
# round to decimal
green=$(printf "%0.f" "${green}")
#### blue channel value ####
# rgbformulae 15 in gnuplot
local blue="$(bc -l <<< "255 * s(2*${pi}*${nval})")"
# round to decimal
blue=$(printf "%0.f" "${blue}")
# make sure blue is positive
if ((blue < 0))
then
blue=0
fi
### whole rgba value
local rgba="#"
rgba+="$(printf "%02x" "${alpha}")"
rgba+="$(printf "%02x" "${red}")"
rgba+="$(printf "%02x" "${green}")"
rgba+="$(printf "%02x" "${blue}")"
echo "${rgba}"
}
# data without blank lines
data="$(sed -E "/^[[:space:]]*$/d" "${in_data}")"
# number of lines
nline=$(wc -l <<< "${data}")
# get the minimum and maximum value of the 4-th column
min_max=($(awk '{ print $4 }' <<< "${data}" | sort -g | sed -n '1p;$p'))
# array of colors for each point
colors=()
while read -r line
do
colors+=($(value2rgba "${line}" "${min_max[@]}"))
done < <(awk '{ print $4 }' <<< "${data}")
# gather coordinates into one row
coords=($(awk '{ print $1,$2,$3 }' <<< "${data}"))
gnuplot << EOF
set term pngcairo
set out "${out_png}"
\$DATA << EOD
${coords[@]}
EOD
nline=${nline}
colors="${colors[@]}"
unset key
splot for [i=0:nline-1] \$DATA \
u (column(3*i+1)):(column(3*i+2)):(column(3*i+3)) \
pt 1 lc rgb word(colors, i+1)
EOF
이 스크립트의 gnuplot 5
나는 당신의 gnuplot 필요가 없다 생각 테스트,하지만 matlab에 또는 옥타브를했다. 이 프로그램으로 원하는 것을 쉽게 할 수 있습니다. –
네 번째 열에서 색과 투명도를 모두 결정 하시겠습니까? 0과 1 사이가 아닐 때 무엇을하고 싶습니까? – user8153
@ user8153 네 번째 열에서 색과 투명도를 결정하고 싶습니다. 네 번째 열 값은 항상 내 데이터에 대해 양의 값을 가지며 1보다 작거나 클 수 있습니다. 1보다 큰 경우 1에 가까울수록 더 투명하게 보이기를 바랍니다. 네 번째 열 스케일에서 로그 열을 가정하고 로그 눈금이 1 주위에서 대칭이라고 가정하면 10^-n에서 10^n까지를 의미합니다. 여기서 n은 힘이며, 그러면 색상 막대의 가운데가 1이되고, 가장 투명합니다. – James