3

gnuplot でラベルの textcolor プロパティを設定して、色のパレットを切り替えようとしています。
より正確には、ラベルの各文字、たとえば"Number of Connections"を異なる色にする必要がありますが、指定したカラー パレットに従います。
以下の方法で試してみましたが、文字列の範囲の真ん中の色だけで失敗しました。

set palette model RGB defined ( \
0 '#F46D43',\
1 '#FDAE61',\
2 '#FEE08B',\
3 '#E6F598',\
4 '#ABDDA4',\
5 '#66C2A5' )
set y2label "Number of Connections" textcolor palette
4

1 に答える 1

3

残念ながら、gnuplot は文字列全体にしか色を付けることができません"Number of Connections"frac追加オプションを使用して色に影響を与えることができます。
ただし、ここにあなたが探していたものを達成する方法があります。ただし、以下で説明するように、いくつかの手動設定が必要です。

# define the location of your plot:
bm = 0.15
lm = 0.12
rm = 0.75
tm = 0.90

# letter spacing - play with this as needed:
STRDIST = 0.03

# set up the plot window:
set lmargin at screen lm
set rmargin at screen rm
set bmargin at screen bm
set tmargin at screen tm

# place the colorbar in a defined location:
set colorbox vertical user origin rm+0.1,0.15 size .05,tm-bm

# define your palette:
set palette model RGB defined ( \
0 '#F46D43',\
1 '#FDAE61',\
2 '#FEE08B',\
3 '#E6F598',\
4 '#ABDDA4',\
5 '#66C2A5' )

# your label
LABEL = "Number of Connections"
# the 'length' of LABEL, unfortunately counted manually:
LEN_LABEL = 21.0 # IMPORTANT, declare as float

# use a loop to individually place each char of the string on the plot:
do for [i=1:LEN_LABEL]{\
set label i LABEL[i:i] at screen 0.8,bm+((i-1.)*STRDIST) \
    rotate by 90 textcolor palette frac i/LEN_LABEL\
}

# dummy function plot (so that there's something to see):
plot '+' using ($1):(sin($1)):(0.5*(1.0+sin($1))) w l lw 3 lc pal not

何が起こっている:

  1. プロットとカラーバーの位置を定義します。これにより、それらがどこにあるかが正確にわかり、「疑似」ラベルを正確に配置できます。
  2. 変数STRDISTは、個々の文字の間隔を空けるために使用されます。これは不器用ですが、要点はわかります。良い結果を得るためにそれで遊んでください。
  3. 残念ながら、gnuplot は文字列の長さを計算できないようですLEN_LABEL
  4. -loop を使用してラベル文字列の各文字をプロットに配置し、追加オプションdo forを使用してカラー パレットから色を割り当てます。は、カラー パレットで最も低く、「最も高い」色です。ここでは、ループ カウンターを利用して、パレットから等間隔の色を指定します。注:これが、整数またはすべてではなく浮動小数点数として宣言することが重要である理由ですが、最後の反復は. fracfrac 0.0frac 1.0LEN_LABELfrac 0
  5. plot '+' ...コマンドはこちらのサイトから拝借。

上記の例をコピーして貼り付けると得られるプロットは次のようになります。

カラフルなラベル

「ラベル」の開始点で遊んで、STRDIST好みのラベルを生成/配置します。

于 2013-07-29T15:28:14.960 に答える