GNUPLOT:将键条目与多图合并 [英] GNUPLOT: Merge key entries with multiplot

查看:124
本文介绍了GNUPLOT:将键条目与多图合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一张图中绘制一个datfile的多个数据项.对于每个数据列,我想使用黑色(不同点划线)和彩色点.我发现了一般的操作方法(首先绘制线(),然后绘制点(with points),然后将图例条目彼此重叠).例如,在这篇文章中对此进行了解释: 在gnuplot中合并键条目

I would like to plot several data colmuns of a datfile in one graph. For each data columnI would like to use a black (differently dashed) line and a coloured point. I found out how to do it in general (by plotting first the line (with lines) and then the points (with points) and afterwards shifting the legend entries on top of each other). This is explained for example in this post: Merge key entries in gnuplot

但是对于我来说,它不能完全正常工作.我有三个问题:

But it is not fully working in my case. I have three problems:

首先:我想在图例旁边加上一个box.但这在我将图例条目彼此重叠时不起作用...

First: I would like to have a box around the legend. But this doesnot work when I shift the legend entries on top of each other...

第二:我想加入一个rectangle object.不知何故,这总是在绘制的线条之上,除了最后一条...

Second: I would like to include a rectangle object. Somehow this always is on top of the plotted lines except the last one...

第三个问题:xticlabels是针对每个图相互绘制的.这就是为什么他们似乎大胆而不应该这样做.我发现我应该隐藏" tics(就像我对borderlabels所做的那样),但是对于tics某种程度上它不起作用...

And the third problem: The xticlabels are plotted for each plot on each other. That is why they seem to be bold which they should not. I found out that I should "hide" the tics (like I do with the border and the labels) but it doesnot work for the tics somehow...

您对我有什么提示吗? 最好的祝福, 塞巴斯蒂安 @ewcz

Do you have some hints for me? Best regards, Sebastian @ewcz

#dataset.dat
"\\footnotesize r/R"    "\\footnotesize OP1"    "\\footnotesize OP2"
0.132   1.018   0.872
0.162   0.940   0.796
0.191   1.014   0.848
0.221   1.043   0.934
0.250   1.010   0.935
0.279   0.987   0.938
0.309   0.962   0.930
0.338   0.929   0.921
0.368   0.897   0.922
0.397   0.876   0.932
0.426   0.831   0.919
0.456   0.795   0.884

#Start terminal
set terminal epslatex size 7.8cm, 6.1cm font ",10" 
#Legend settings
pointSize = 1
yticsScale =1
keySpacing = pointSize*yticsScale*1.25
keyY = 15.5
keyX = 0.975
set key vertical Left reverse width -0.5 height +0 font ",16"
set key opaque
set key autotitle columnheader
set key bottom right spacing -1
#Hide border & labels
set border 0
set xlabel " "
set ylabel " "
#Format of axis numbers
set format xy '$\%g$'
set format x '\footnotesize \%10.1f'
set format y '\footnotesize \%10.1f'
#Format tics
set xtics 0,0.1 out nomirror
set xtics offset -0.2,0
set mxtics 5
set ytics 0.6,0.1 out nomirror
set ytics offset 0.4,0
set mytics 5
#Background grid setting
set grid
show grid
set object 1 rectangle from 0.132, graph 0 to 0.456, graph 1 fillcolor rgb "#A9A9A9" fs pattern 1 noborder behind
#Margins
set lmargin 5.9
set rmargin 0.5
set bmargin 3.5
#Axis range settings
set xrange [0:0.535]
set yrange [0.6:1.2]
#Format lines, boxes...
set style line 4 lt 1 lc rgb 'black' lw 2 pt 13 ps 1.25 dt 4
set style line 5 lt 1 lc rgb 'black' lw 2 pt 4 ps 1.0 dt 5
#Multiplot
set multiplot
set origin 0,0
set size 1,1
#Plots
set key at graph keyX, character keyY
plot 'dataset.dat' using 1:2 with lines ls 4, \
'dataset.dat' using 1:2 with points ls 4 lc rgb "#71da71" title " "
#Label settings
set border
set xlabel '\small $r/D_T\;[-]$' offset 0,+0
set ylabel '\small $c_{m2} \cdot A_{T}/Q_T\;[-]$' offset +10.5,+0
#Last Plot
keyY = keyY - keySpacing
set key at graph keyX, character keyY
plot 'dataset.dat' using 1:3 with lines ls 5, \
'dataset.dat' using 1:3 with points ls 5 lc rgb "#4da6ff" title " "
#End of code
unset multiplot

推荐答案

我会提出以下建议:

  1. 由于两个图中的键都是独立的,所以最直接的解决方案可能是使用set object rectangle手动绘制包围盒(请参见下文)(尽管这可能需要手动调整盒子的大小) ).
  2. 该矩形位于绘制的线条的顶部,因为第二个绘制重复了该矩形.从某种意义上说,相对于第二个图,此第二个副本为behind,但是由于此层位于第一个图的顶部,因此它覆盖了由第一个plot绘制的元素.可以通过使用unset object 1在第二个情节的上下文中删除对象来摆脱这种情况.
  3. ticslabels等类似的问题.在下面的代码中,所有定义都在第一个plot命令之前移动,然后相对于第二个图移动unset.
  1. Since the keys in both plots are independent, perhaps the most straightforward solution would be to draw the encompassing box manually (see below) by using set object rectangle (although this might need some manual "tweaking" of the size of the box).
  2. The rectangle is on top of the plotted lines since it is duplicated by the second plot. In a sense, this second copy is behind with respect to the second plot, but since this layer is on top of the first plot, it covers the elements plotted by the first plot. One can get rid of this by deleting the object in the context of the second plot with unset object 1.
  3. It is a similar issue with the tics,labels,etc. In the code below, all the definitions are moved before the first plot command and then unset with respect to the second plot.

进行了这些修改后,脚本将如下所示:

With these modifications the script would look like:

#Start terminal
set terminal epslatex size 7.8cm, 6.1cm font ",10"

#Legend settings
pointSize = 1
yticsScale =1
keySpacing = pointSize*yticsScale*1.25
keyY = 15.5
keyX = 0.975
set key vertical Left reverse width -0.5 height +0 font ",16"
set key opaque
set key autotitle columnheader
set key bottom right spacing -1

#Format of axis numbers
set format xy '$\%g$'
set format x '\footnotesize \%10.1f'
set format y '\footnotesize \%10.1f'
#Format tics
set xtics 0,0.1 out nomirror
set xtics offset -0.2,0
set mxtics 5
set ytics 0.6,0.1 out nomirror
set ytics offset 0.4,0
set mytics 5
#Background grid setting
set grid
show grid
set object 1 rectangle from 0.132, graph 0 to 0.456, graph 1 fillcolor rgb "#A9A9A9" fs pattern 1 noborder behind
#Margins
set lmargin 5.9
set rmargin 0.5
set bmargin 3.5
#Axis range settings
set xrange [0:0.535]
set yrange [0.6:1.2]
#Format lines, boxes...
set style line 4 lt 1 lc rgb 'black' lw 2 pt 13 ps 1.25 dt 4
set style line 5 lt 1 lc rgb 'black' lw 2 pt 4 ps 1.0 dt 5
#Multiplot
set multiplot
set origin 0,0
set size 1,1
#Plots
set key at graph keyX, character keyY

#simulate key box
set object 2 rectangle from graph keyX, character keyY + 0.5*keySpacing to graph 0.65, character keyY - 1.5*keySpacing fillcolor rgb "#FFFFFF" fs pattern 2 border rgb "black"

set xlabel '\small $r/D_T\;[-]$' offset 0,+0
set ylabel '\small $c_{m2} \cdot A_{T}/Q_T\;[-]$' offset +10.5,+0

plot \
  'dataset.dat' using 1:2 with lines ls 4, \
  'dataset.dat' using 1:2 with points ls 4 lc rgb "#71da71" title " "

#unset these so that they are not duplicated by the following plot command
unset border
unset xtics
unset ytics
unset xlabel
unset ylabel

unset object 1
unset object 2

#Last Plot
keyY = keyY - keySpacing
set key at graph keyX, character keyY

plot \
  'dataset.dat' using 1:3 with lines ls 5, \
  'dataset.dat' using 1:3 with points ls 5 lc rgb "#4da6ff" title " "

然后生成(我使用了standalone epslatex终端.这可能是字体问题,但是ylabel似乎将从稍大的水平偏移量中受益):

This then produces (I used standalone epslatex terminal. It might be some font issue, but it seems that the ylabel would benefit from slightly larger horizontal offset):

这篇关于GNUPLOT:将键条目与多图合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆