2017-11-10 58 views
0

私はsplot(xyz値)を使って4dプロットをプロットしようとしています。私は第4列を熱の色として示したいと思います。今まで、私は大丈夫です。私が理解できないことは、回答をオンラインで検索した後、ドットの色を透明にすることですが、その値に基づいて透明度が異なります。Gnuplot 4dデータに基づいて異なる透明度のマップカラーバー

たとえば、のは、私は次のデータセットを持っているとしましょう:

0 0 0 0.1 
0 0 1 0.2 

0 1 0 0.2 
0 1 1 2 

1 0 0 1 
1 0 1 3 

1 1 0 0.5 
1 1 1 4 

は今、私はそのようなのように(4列目用)カラーバーを作りたい:近い第四列の値がにあります1であれば、図のドット/ポイントがより透明になります。私が見たすべての場所は、カラーバー全体に対して一様な透明性しか与えられません。

これまで誰かがこれを扱っているのだろうか、それをどうするか考えているのだろうか。 ありがとうございます!

+0

で試験しました。これらのプログラムでは、あなたが望むことを行う方がはるかに簡単です。 –

+0

4番目の列で色と透明度の両方を決定しますか? 0と1の間にないときに何をしたいですか? – user8153

+0

@ user8153 4番目の列は色と透明度の両方を決定したいと思います。 4番目の列の値は常にデータに対して正の値をとり、1よりも小さくても大きくてもかまいません。1より大きい場合は、1に近いほど透明になります。 log scaleでlog scaleを仮定し、対数尺度が1の対称であると仮定すると、10^-nから10^nになります。ここでnはべき乗で、カラーバーの中央が1、最も透過的です。 – James

答えて

0

透明度をどのように値に依存させるかを完全には理解していませんでしたので、一般的な答えを示します。ここでは、透明関数を自分で代用することができます。

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の必要はありませんと思いますが、Matlabのか、オクターブのgnuplot 5.

関連する問題