gnuplot:根据所绘制的轴在左侧或右侧设置键

时间:2017-01-14 01:46:04

标签: key gnuplot

我正在使用ytics和y2tics,因为我的数据范围差异很大。通过使用两个轴,所有数据都按比例表示。请参阅此示例图片:sample image

"集群","主机"和" vsan"数据使用y2axis,其余使用yaxis。如何根据绘制的轴将键移动到左上角或右上角(图中)?

以下是我的代码的摘录:

set y2tics
set ytics nomirror
plot "data" using 1:2 title "Clusters" linecolor rgb "black" axes x1y2, \
        '' using 1:3 title "Hosts" linecolor rgb "blue" axes x1y2,\
        '' using 1:4 title "vSAN" linecolor rgb "cyan" axes  x1y2,\
    '' using 1:5 title "VMs" linecolor rgb "purple" axes x1y1,\
        '' using 1:6 title "⚫" linecolor rgb "green"  axes x1y1,\
        '' using 1:7 title "⚪" linecolor rgb "red" axes x1y1

以下是一些示例测试数据:

2016-12-18 22 131 0 1179 1024 155
2016-12-19 22 131 0 1179 1025 154
2016-12-20 22 131 0 1178 1025 153
2016-12-21 22 129 0 1180 1026 154
2016-12-22 22 132 0 1182 1014 168
2016-12-23 22 133 0 1182 1016 166
2016-12-24 22 133 0 1187 1016 171
2016-12-25 22 133 0 1187 1016 171
2016-12-26 22 133 0 1187 1016 171
2016-12-27 22 133 0 1187 1016 171
2016-12-28 22 133 0 1189 1017 172
2016-12-29 22 133 0 1189 1018 171
2016-12-30 22 133 0 1189 1018 171
2017-01-01 22 133 0 1189 1018 171
2017-01-02 22 133 0 1189 1018 171
2017-01-03 22 133 0 1185 1020 165
2017-01-04 22 133 0 1183 1018 165
2017-01-05 22 133 0 1183 1017 166
2017-01-06 22 133 0 1174 1018 156
2017-01-07 22 133 0 1173 1018 155
2017-01-08 22 133 0 1173 1018 155
2017-01-09 22 133 0 1175 1011 164
2017-01-10 22 131 0 1170 1004 166
2017-01-11 22 131 0 1170 1004 166
2017-01-13 22 131 0 1162 998 164

根据Maij的回答更新了样本图片:

enter image description here

2 个答案:

答案 0 :(得分:0)

如果“向左侧或右侧”表示图例本身的侧面,则可以创建两列图例。由于您有六条曲线,请将参数maxrows设置为3,因此您将有3行和2列。

set term pngcairo size 1024,700
set output 'key.png'
set key right outside maxrows 3
set y2tics
set ytics nomirror
plot sin(x) t '1' axes x1y2,\
2*sin(x) t '2' axes x1y2,\
3*sin(x) t '3' axes x1y2,\
4*sin(x) t '4' axes x1y1,\
5*sin(x) t '5' axes x1y1,\
6*sin(x) t '6' axes x1y1

enter image description here

答案 1 :(得分:0)

如果“左侧或右侧”表示图形区域的两侧,则可以使用multiplot环境。我们必须手动调整边距,我们必须注意不要在错误的一面打印y-tics。

set samples 1000
set xrange [0:2*pi]

# The plots must overlap, so we set the margins manually.
# We have to play with the numbers, the depend on the terminal.
set lmargin at screen 0.25
set rmargin at screen 0.75

set key outside

set terminal pngcairo size 800,400
set output "two_keys.png"

set multiplot

   # no ytics on the right side for the first plot
   set ytics nomirror
   set key left
   plot sin(x) lt 2, \
        cos(x) lt 3

   # no ytics on the left side for the second plot
   unset ytics
   set y2tics
   set y2range [-10:10]

   set key right
   plot tan(x) axis x1y2 lt 4

unset multiplot

这是gnuplot 4.6:plot with two legends

的结果