2016-11-28 16 views
1

プロットカラーを変更するために、16進値またはRGBトリプルの代わりにカラー名を使用する方法はありますか?私が必要なのはsimilar to the first answer in this postです。私の入力データ(input.dat)は次のとおりです。RGBカラー名の問題

1 1 2 0 magenta 
1 2 2 0 red 
1 3 2 0 green 
1 4 2 0 black 

簡単なテスト:

set xrange [0:10] 
set yrange [0:10] 
plot "input.dat" using 1:2:3:4:5 with vectors lw 3 lc rgb variable 

答えて

0

lc rgb variableが色にそれらを評価する前に整数に任意の文字列を変換し、これはしません文字列 "red"を数値0xff0000に変換します。したがって、私たちは独自の変換関数を定義する必要があります。

回答はhttps://stackoverflow.com/a/35729052/7010554です。ここで可能な実装である:

colorSet(name, rgb) = sprintf("color_%s = %d", name, rgb) 
colorGet(name) = value(sprintf("color_%s", name)) 

eval colorSet("magenta", 0xff00ff) 
eval colorSet("red",  0xff0000) 
eval colorSet("green", 0x00ff00) 
eval colorSet("black", 0x000000) 
eval colorSet("dark_yellow", 0xc8c800) 

print colorGet("green") 
print color_green 

set xrange [0:10] 
set yrange [0:10] 
plot "input.dat" using 1:2:3:4:(colorGet(stringcolumn(5))) with vectors lw 3 lc rgb variable 

arrows with color names read from file

機能colorSet(name, rgb)と `colorGet(名前が)、COLOR_REDフォームCOLOR_GREENの名前、で作成したアクセス変数ます...これらの変数の値は、対応するrgb値

色は好きなように定義できます。名前にはハイフンを使用できません。 gnuplotの内部カラー定義は、コマンドshow colorsで表示されます。

+0

私自身の変換機能を定義することを期待していませんでした。色の名前が定義されているので、もっと簡単になると思いました。しかし、私の問題を解決した@maijに感謝します。 – ACR

関連する問題