5

gnuplotでラベルとラインを同じ色に設定する方法に関連していますが、まったく同じではありません...このコードを使用すると:

set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"

set xrange [0:3]
set yrange [0:3]

# function to get style index for coloring:
getCol(x) = (x==0)?1:((x==1)?2:3);

plot \
  '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses \
    lc variable notitle, \
  "" using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
    textcolor variable point linestyle 1 pointtype 7 lc variable \
    font ",6" offset character 1.0,character 1.0  notitle
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e

... この出力が得られます。

gnuplot-out

の色付けにはすべて問題ないように見えますがimpulses、 のlabels場合、アプローチは機能しているように見えますが、色が別のインデックスから読み取られているようです ?!

では、インパルス ラインと同じ関数を使用して、ポイントとラベルに同じ可変色を持たせるにはどうすればよいでしょうか。これはgnuplot 4.6パッチレベル1にあります...

4

1 に答える 1

3

のカラー インデックスは線種impulsesの選択に使用され、 の場合labelsは線種が使用されます。この動作は、現在の開発バージョンにも存在します。ドキュメントによると、の動作labelsは正しいです。help linecolor variable: "lc variable入力データの 1 つの列から読み取った値を線種インデックスとして使用するようにプログラムに指示しますtc variable。". バグ、機能、または間違ったドキュメントですか?

lc palette回避策として、適切に定義されたを使用できますpalette

set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"

set palette defined (1 "aquamarine", 2 "blue", 3 "coral")
unset colorbox
set xrange [0:3]
set yrange [0:3]

# function to get style index for coloring:
getCol(x) = (x==0)?1:((x==1)?2:3)

unset key
plot \
  '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses lc variable, \
  '' using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
    tc palette point ls 1 pt 7 lc palette offset 1,1
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e

これにより、次の結果が得られます。 ここに画像の説明を入力

実際のケースでも回避策が機能することを願っています。何らかの理由でパレットを再定義できないlc rgb variable場合は、 を使用できます。この場合、最後の列はそれぞれの RGB カラーの整数表現でなければなりません。

set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "aquamarine"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
set style line 3 linetype 1 linewidth 2 pointtype 3 linecolor rgb "coral"

set xrange [0:3]
set yrange [0:3]

rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
rgb1 = rgb(2, 215, 245) # something like aquamarine
rgb2 = rgb(0, 0, 255)
rgb3 = rgb(245,140,2)
getCol(x) = (x==0)?rgb1:((x==1)?rgb2:rgb3)

unset key
plot \
  '-' using ($1+0.5):($2+0.5):(getCol($2)) with impulses \
    lc rgb variable, \
  '' using ($1+0.5):($2+0.5):(stringcolumn(2)):(getCol($2)) with labels \
    tc rgb variable point ls 1 pt 7 lc rgb variable offset 1,1
0 0
1 1
1.5 1
2 2
e
0 0
1 1
1.5 1
2 2
e

RGB値を微調整するだけでよい場合があります。

ただし、これが本当にバグなのかどうかを確認するために、gnuplot メーリングリストでこの議論を取り上げます。

于 2013-08-21T22:38:56.427 に答える