1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gnuplotで値をカラーマップする際に透明色を使う

Last updated at Posted at 2020-05-06

環境: gnuplot 5.2

(1) データの値をカラーマップする(不透明色)

# test.txt
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
...

の3列目の値をgnuplotでカラーマップしたい時には、

set palette define(0 "0xffffff", 1 "0xff0000");
plot "test.txt" u 1:2:3 pt 7 ps 5 lc palette

とすれば、以下の図のように3列目の値を0xffffff(白)から0xff0000(赤)で表現できる。
test_2.png

(2) マッピングカラーに透明色を使う

次に(1)で0xffffff(白)にしていた箇所を透明色にする。
通常lcで透明色を使用する場合には、RGB(0xRRGGBB)ではなくARGB(0xAARRGGBB)を使用して、アルファ値(AA)を指定すればOK。
一方、カラーマッピングで透明色を使おうと思うと、gnuplot 5.2の時点ではpalette内でARGBを使用できず、(1)の方法は使えなさそうなので、関数を定義した。

  1. まず3列目の最大値を拾う。(gnuplotで最大値、最小値を求める@krtf)
# 3列目の最大値を拾う
x0 = 1e38
x1 = -1e38

grabx(x) = (x<x0) ? x0=x : (x>x1) ? x1=x : 0
set table "/dev/null"
plot "test.txt" using (grabx($3))
unset table
  1. アルファ値付きのカラー関数を定義する。(Gnuplot: transparency of data points when using palette: 1Answer)
# rgb
r(x) = 1
g(x) = 0
b(x) = 0

# lcの設定 
Transp(x) = int((1-x*x)*0xff)<<24  # 透過度 (0x00 ~ 0xff)
Color(x) = Transp(x) + (int(r(x)*0xff)<<16) + (int(g(x)*0xff)<<8) + int(b(x)*0xff)
  1. plotする。
plot 'test.txt' u 1:2:(Color($3/(x1))) pt 7 ps 5 lc rgb var

このような感じで透明色を使える。
test.png

$r(x), g(x), b(x)$や$Transp(x)$の関数系をいじれば、色変化を調整できる。
exportする場合には、pdfcairoじゃないと透過が無効になるのでご注意。

もっと単純な方法などあれば教えてください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?