Gnuplot:相对于x1轴绘制x2轴 [英] Gnuplot: Plot x2 axis with respect to x1 axis

查看:113
本文介绍了Gnuplot:相对于x1轴绘制x2轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎很难在网上找到该问题的答案.标题是基本问题,但更具体地说,我希望有两个x轴,一个在图的顶部,而另一个在底部.但是,这不是简单的关系,即x2!= 5 * x1或类似的关系.该关系由数据文件本身给出.因此,更具体地说,我有一个看起来像这样的文件:

I seem to be having some difficulty finding the answer to this question online. The title is the basic question, but to be more specific I would like to have two x axes, one at the top of the figure that is dependent on the one at the bottom. However, this is not a simple relationship, i.e. x2!=5*x1 or something like that. The relationship is given by the data file itself. So to be more specific I have a file that looks something like this:

 V     T       P
2.0   15.0   0.586
3.0   17.4   0.798
4.0   25.3   1.023
5.0   28.9   1.124
6.0   30.2   1.456

我想在x1y1轴上绘制相对于(wrt)P的T的图,并在x2y1轴上绘制T wrt V.因此,x1轴将在x1的相应位置显示P范围,而x2将在x1的相应位置显示V范围,即x1轴上的0.586在同一位置在x2轴上有2.0.这实际上在Gnuplot中是可能的,还是我必须与两个x轴有关系才能做到这一点?任何帮助将不胜感激.先感谢您.

I would like to make a plot of T with respect to (wrt) P on the x1y1 axes and have T wrt V on the x2y1 axes. So the x1 axis would display the P range and x2 would display the V range in the corresponding places of x1, i.e. 0.586 on x1 axis would have 2.0 on x2 axis at the same place. Is this actually possible in Gnuplot or do I have to have a relationship with the two x axes to do this? Any help would be greatly appreciated. Thank you in advance.

推荐答案

此处是实现此目的的方法.我首先向您展示脚本和结果,然后再说明步骤:

Here is how you can achieve this. I first show you the script and the result, and later explain the steps:

reset
set xtics nomirror
set x2tics
set autoscale xfix
set autoscale x2fix
set xlabel 'P'
set ylabel 'T'
set x2label 'V'
plot 'data.txt' using 3:2 with linespoints ps 2 lw 2 title 'T wrt P', \
     '' using 3:2:x2tic(1) axes x2y1 with points ps 2 lw 2 title 'T wrt V'

我首先在x1y1上绘制 T wrt P .之后,我在x2y1上绘制 T wrt V ,并为此使用 P 的范围和刻度位置,但将 V 值用作刻度x2轴的标签.这样会给出 P 的线性比例,并相应地调整 V .

I first plot T wrt P on x1y1. Afterwards I plot T wrt V on x2y1 and use for this the range and tic positions of P, but use the V values as tic labels for the x2 axis. This gives a linear scale for P and adapts V accordingly.

为此,您必须使用set autoscale xfixset autoscale x2fix.这样会使用精确的范围,并且不会将轴扩展到下一个主要点,这仅适用于x轴,而不会扩展到具有自定义点的x2轴.

In order for this to work you must use set autoscale xfix and set autoscale x2fix. This uses the exact ranges and does not expand an axis to the next major tics, which would be done only for the x axis, but not for the x2 axis, which has custom tics.

您当然也可以颠倒这个过程,对 V 使用线性刻度,并调整 P 抽动.无论如何,对于放置在x2tic上的自定义标记,数字的使用方式与它们在数据文件中的格式一样.

You could of course also reverse the process and use a linear scale for V and adapt the P tics. In any case, for the custom tics, which are placed with xtic() or x2tic, the numbers are used like they are formatted in the data file.

reset
set xtics nomirror
set x2tics 1
set autoscale xfix
set autoscale x2fix
set xlabel 'P'
set ylabel 'T'
set x2label 'V'
plot 'data.txt' using 1:2:xtic(3) with linespoints ps 2 lw 2 title 'T wrt P', \
     '' using 1:2 axes x2y1 with points ps 2 lw 2 title 'T wrt V'

在这里,两条绘图线都显示了点,以证明它们确实重合.

Here, the points are shown for both plot lines, to demonstrate, that they really coincide.

为了使一个命令仅生成xtics,可以将NaN用作y值.并且,如果仅某些自定义标记应为标签,则需要在x2tic调用中进行适当的检查.在这里,我只为所有偶数行设置标签,$0是当前行号,从0开始):

In order to have the one command only generating the xtics, one can use NaN for the y-value. And if only some of the custom tics should be labels, one needs an appropriate check in the x2tic call. Here, I set labels only for all even rows $0 is the current row number, starting from 0):

reset
set xtics nomirror
set x2tics
set autoscale xfix
set autoscale x2fix
set xlabel 'P'
set ylabel 'T'
set x2label 'V'
plot 'data.txt' using 3:2 with linespoints ps 2 lw 2 title 'T wrt P', \
     '' using 3:(NaN):x2tic((int($0) % 2) ? '' : stringcolumn(1)) axes x2y1 t ''

结果:

这篇关于Gnuplot:相对于x1轴绘制x2轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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