The horizontal key displays in vertical in GNUPLOT

一曲冷凌霜 提交于 2020-01-11 12:09:08

问题


In gnuplot, I used the horizontal key, but it shows me vertical on the output screen. I tried every alternative but found difficult to do that.

set terminal wxt size 600,600 enhanced font 'times new roman,10' persist
set xlabel "X-Axis"
set ylabel "Y-Axis"
set multiplot layout 2,3
set key box
set key horiz
set key at screen 0.5, 0.40
set title "1st"
set xrange [0:20]
plot    tan((pi/180)*x)   title "Analytical"   w l  ls 1,\
        tan(2*(pi/180)*x) title "Observed"     w lp ls 2,\
        tan(3*(pi/180)*x) title "Experimental" w lp ls 3

set title "2nd"
set xrange [0:20]
plot    tan((pi/180)*x)   title "Analytical"   w l  ls 1,\
        tan(2*(pi/180)*x) title "Observed"     w lp ls 2,\
        tan(3*(pi/180)*x) title "Experimental" w lp ls 3

set title "3rd"
set xrange [0:20]
plot    tan((pi/180)*x)   title "Analytical"   w l  ls 1,\
        tan(2*(pi/180)*x) title "Observed"     w lp ls 2,\
        tan(3*(pi/180)*x) title "Experimental" w lp ls 3

unset multiplot

Is there any alternative possible?? See the plot by click on the output below:


回答1:


You can force the legend to consist of a single row by specifying set key vertical maxrows 1:

set xlabel "X-Axis"
set ylabel "Y-Axis"
set multiplot layout 2,3
set key at screen 0.5, 0.40 center vertical height 1 box maxrows 1
set title "1st"
set xrange [0:20]
plot    tan((pi/180)*x)   title "Analytical"   w l  ls 1,\
    tan(2*(pi/180)*x) title "Observed"     w lp ls 2,\
    tan(3*(pi/180)*x) title "Experimental" w lp ls 3

set title "2nd"
set xrange [0:20]
plot    tan((pi/180)*x)   title "Analytical"   w l  ls 1,\
    tan(2*(pi/180)*x) title "Observed"     w lp ls 2,\
    tan(3*(pi/180)*x) title "Experimental" w lp ls 3

set title "3rd"
set xrange [0:20]
plot    tan((pi/180)*x)   title "Analytical"   w l  ls 1,\
    tan(2*(pi/180)*x) title "Observed"     w lp ls 2,\
    tan(3*(pi/180)*x) title "Experimental" w lp ls 3

unset multiplot




回答2:


Each of your 3 plots generates a separate key. The multiplot layout places all 3 plots on the same page, but still each one is only 1/3 of the page in width and that sets the maximum horizontal size of its key. In the example you re-position each key to the same place at the bottom of the page so that they lie exactly on top of each other. This does not change their size or shape, only their position.

What you can do instead is to manually place each title on the page without reference to the auto-generated key. In order to leave room for the manually placed key entries you can give explicit multiplot layout margins.

set multiplot layout 1,3 margins .1, .9, .3, .9
set key
plot    tan((pi/180)*x)   title "Analytical"   at screen .25,.1 w l  ls 1,\
        tan(2*(pi/180)*x) title "Observed"     at screen .50,.1 w lp ls 2 ,\
        tan(3*(pi/180)*x) title "Experimental" at screen .75,.1 w lp ls 3
unset key
plot ...
plot ...
unset multiplot

Placing a box around the manually positioned titles is a separate question.



来源:https://stackoverflow.com/questions/50368785/the-horizontal-key-displays-in-vertical-in-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!