这是您如何实现这一目标的方法。我首先向您展示脚本和结果,然后再解释步骤:
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'
![在此处输入图像描述](https://i.stack.imgur.com/BGlsT.png)
我首先在 上绘制T wrt Px1y1
。之后,我绘制T wrt V onx2y1
并为此使用P的范围和 tic 位置,但使用V值作为 x2 轴的 tic 标签。这给出了P的线性比例并相应地调整V。
为了使其工作,您必须使用set autoscale xfix
and set autoscale x2fix
。这使用了精确的范围,并且不会将轴扩展到下一个主要抽动,这仅适用于 x 轴,而不适用于具有自定义抽动的 x2 轴。
当然,您也可以反转该过程并为V使用线性比例并调整P tics。xtic()
在任何情况下,对于使用或放置的自定义 tic,x2tic
数字的使用方式就像它们在数据文件中的格式一样。
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'
![在此处输入图像描述](https://i.stack.imgur.com/33fp9.png)
在这里,显示了两条绘图线的点,以证明它们确实重合。
为了让一个命令只生成 xtics,可以使用NaN
-value y
。如果只有一些自定义抽动应该是标签,则需要在x2tic
调用中进行适当的检查。在这里,我只为所有偶数行设置标签,$0
即当前行号,从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 ''
结果:
![在此处输入图像描述](https://i.stack.imgur.com/JGsrk.png)