gnuplot:将y2轴tic施加在y tics位置上 [英] gnuplot: force y2 axis tics on y tics position

查看:54
本文介绍了gnuplot:将y2轴tic施加在y tics位置上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从另一个答案中的设置链接中得到启发,我想绘制一个图形并显示不同的比例轴.

inspired from the set link in another answer i want to plot a graph and show different scale axis.

set grid mytics
set xrange[1:5]  
set yrange[0:3]
set y2range[0:30]
set xlabel "a"   
set ylabel "b"  
set ytics 
set y2label "c"
set mytics 2

ca = 0.05
cb = 0.5

f(x) = sin(x*pi/180)*cb *1000
i(x) = asin(x/1000 / cb )/pi*180
set link y2 via f(y) inverse i(y)

pl asin(ca /x)/pi*180 title "a"

它按预期绘制了图和轴,但是我想要的是y2轴上的抽芯在ytics上是精确的(尽管它们将是非整数)

it draws the plot and the axis as expected but what i want is that the tics on the y2 axis are exact on the ytics (although they will be non round numbers)

推荐答案

没有其他选择,例如 6 在轴上平均分布tic(就像使用 set my2tics 7 一样).但是您可以手动添加tic,因为您知道功能范围.

There is no option to put e.g. 6 equally distributed tics on an axis (like it would be done with set my2tics 7). But you can add the tics manually because you know the function range.

首先,您需要使用

set y2tics (f(0))

然后您可以循环设置所有次要和主要抽动:

And then you can set all minor and major tics in a loop:

do for [i=0:6] {
    set y2tics add (f(i/2.0))
    set y2tics add ('' f(i/2.0 + 0.25) 1)
}

请注意,以浮点增量循环不起作用.

Note, that looping with a float increment doesn't work.

因此您的完整脚本如下所示:

So your complete script looks like this:

reset
set grid mytics
set xrange[1:5]  
set yrange[0:3]
set y2range[0:30]
set xlabel "a"   
set ylabel "b"  
set ytics nomirror
set y2label "c"
set mytics 2

ca = 0.05
cb = 0.5

f(x) = sin(x*pi/180)*cb *1000
i(x) = asin(x/1000 / cb )/pi*180
set link y2 via f(y) inverse i(y)

set format y2 '%.2f'
set y2tics (f(0)) # clear all automatic y2tics
do for [i=0:6] {
    set y2tics add (f(i/2.0))
    set y2tics add ('' f(i/2.0 + 0.25) 1)
}

pl asin(ca /x)/pi*180 title "a"

结果:

只要知道主要抽动的数量,就有一种方法可以独立于 yrange 设置 y2tics .首先,您使用 unknown 终端进行绘图,然后可以访问 yrange 值作为变量 GPVAL_Y_MIN GPVAL_Y_MAX .不幸的是,人们无法访问一个轴的数量:

There is a way to set the y2tics independent of the yrange as long as the number of major tics is known. First you plot with the unknown terminal, after which you can access the yrange value as the variables GPVAL_Y_MIN and GPVAL_Y_MAX. Unfortunately, one cannot access the number of tics of an axis:

...
set link y2 via f(y) inverse i(y)

set terminal push # save current terminal
set terminal unknown
pl asin(ca /x)/pi*180 title "a"

num_tics = 7
set format y2 '%.2f'
set y2tics (f(GPVAL_Y_MIN)) # clear all automatic y2tics
Y0 = GPVAL_Y_MIN
DY = (GPVAL_Y_MAX - GPVAL_Y_MIN)/(num_tics-1)
do for [i=0:(num_tics-1)] {
    set y2tics add (f(Y0+i*DY))
    set y2tics add ('' f(Y0+(i+0.5)*DY) 1)
}

set terminal pop # restore terminal
replot

这篇关于gnuplot:将y2轴tic施加在y tics位置上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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