タイトルが示すように、プロットの凡例をマルチプロット グラフの下に配置したいと考えています。線のスタイルはすべて同じであるため、プロットの 1 つだけに凡例を追加します。私が遭遇する問題は、 でキーを追加するとset key below
、キャンバス内の (大きな) キーに合うようにプロット自体のサイズが変更されることです。プロットのサイズを維持したいと思います。マルチプロットの追加プロットとしてキーを追加しようとしましたset key inside
が、キーが大きすぎるとプロットに重なる可能性があります。epslatex 端末を使用しています。
16991 次
2 に答える
8
プロットのマージンの位置を調整するのに役立ついくつかの関数を使用してそれを行う方法を次に示します。
#!/usr/bin/env gnuplot
### n: change this parameter to equal the number of data sets to be plotted
n = 3
# t: top margin in pixels
t = 75.0
# b: key height in pixels (bottom margin)
b = 300.0
# h: height of output in pixels
h = 150.0*n + t + b
### define functions to help set top/bottom margins
top(i,n,h,t,b) = 1.0 - (t+(h-t-b)*(i-1)/n)/h
bot(i,n,h,t,b) = 1.0 - (t+(h-t-b)*i/n)/h
### first set up some basic plot parameters
set term pngcairo enhanced size 800,h font 'FreeMono-Bold,14'
set output 'bigkey.png'
set title 'Big Key Plot'
set ylabel 'Y Axis'
set multiplot layout (n+1),1
### First plot
# change only plot command here
currentplot = 1
set tmargin at screen top(currentplot,n,h,t,b)
set bmargin at screen bot(currentplot,n,h,t,b)
unset key
unset xtics
plot sin(1*x) title 'Line 1', \
sin(2*x) title 'Line 2', \
sin(3*x) title 'Line 3', \
sin(4*x) title 'Line 4', \
sin(5*x) title 'Line 5', \
sin(6*x) title 'Line 6', \
sin(7*x) title 'Line 7'
### Middle plot
# copy and paste this code to make more middle plots
currentplot = currentplot + 1
set tmargin at screen top(currentplot,n,h,t,b)
set bmargin at screen bot(currentplot,n,h,t,b)
unset title
replot
### Last plot
# change only plot command here
currentplot = currentplot + 1
set tmargin at screen top(currentplot,n,h,t,b)
set bmargin at screen bot(currentplot,n,h,t,b)
set xlabel 'X Axis'
set xtics
replot
### Last (key) plot
set tmargin at screen bot(n,n,h,t,b)
set bmargin at screen 0
set key center center
set border 0
unset tics
unset xlabel
unset ylabel
set yrange [0:1]
plot 2 t 'Line 1', \
2 t 'Line 2', \
2 t 'Line 3', \
2 t 'Line 4', \
2 t 'Line 5', \
2 t 'Line 6', \
2 t 'Line 7'
unset multiplot
結果は次のとおりです。
手動で調整する必要があるのは、プロットの数と、キーが描画される下マージンのサイズです。コメントは通常、どこを変更する必要があるかを示します。
他のプロットのサイズをまったく同じに保つのが簡単になるように、キーを単独でプロットに入れました。y の範囲が 0 から 1 のときに数値 2 をプロットすると、キー プロットに線が表示されなくなります。
これは主に私の答えhereに基づいています。そのため、すべてのプロットが触れています。プロット間にギャップが必要な場合は、マージン パラメータを追加して top() および bot() 関数を調整できます。
于 2013-02-06T17:40:54.107 に答える
7
詳細がなければ、これが役立つかどうかを判断するのは困難ですが、gnuplot ではキーの位置を絶対的に指定できます。
set key at screen 0.5,screen 0.1 #for example
これにより、好きな場所に移動できるようになる可能性があります...
于 2013-02-05T18:10:49.480 に答える