gnuplot:如何为不同单位添加y2轴比例 [英] Gnuplot: how to add y2 axis scale for different units

查看:83
本文介绍了gnuplot:如何为不同单位添加y2轴比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从文件中绘制数据.数据点以公制为单位.我想在右边以标准单位显示第二个比例尺(y2).

I'm plotting data from a file. The data points are in metric units. I want to show a second scale on the right (y2) that's in standard units.

该文件表示随时间推移的火箭发动机推力.数据以牛顿为单位.我想在左边显示牛顿(自然发生),而在右边显示磅力.转换是一个简单的因子(将N乘以0.2248得到lbf).

The file represents rocket motor thrust over time. The data are in Newtons. I want to show newtons on the left (this happens by itself, naturally) and pounds force on the right. The conversion is a simple factor (multiply N by 0.2248 to obtain lbf).

我可以设置y2tics,如果手动设置y2range,它们将显示在右侧.我不知道该怎么办,是将y2range自动设置为y1range *一个因数.

I can set y2tics and if I set y2range manually, they appear on the right. What I don't know how to do is set y2range automatically to y1range * a factor.

我最终的解决方案是绘制两次,一次在y1上以牛顿为单位,一次在y2上以磅为单位,然后使y2的图几乎不可见:

My eventual solution is to plot twice, once in Newtons on y1 and once in pounds on y2, and make the y2 plot almost invisible:

plot '-' using 1:($2*0.2248) with dots axes x1y2 lc rgb 'white' notitle, \
      '' using 1:2 with lines lc rgb '<color>' title '<title>'


上面的解决方案通常会产生略有不同的y尺度:使用autoragne时,gnuplot将范围四舍五入,因此每个轴上的最高刻度是一个整数,当然,不同单位的舍入也不同.


The solution above often generates slightly different y scales: with autoragne, gnuplot rounds up the range so the top tick on each axis is a round number, and of course the rounding is different for different units.

最终,我最终得到了Python代码,该代码在每个图中都找到了最大推力值,然后我将yrange设置为该数字,并将y2range设置为该数字* 0.2248:

Ultimately I end up with Python code that finds the highest thrust value in each graph, then I explicitly set yrange to that number and y2range to that number * 0.2248:

f.write("set yrange [0:%s]; set y2range[0:%s]\n" % (peak_thrust, peak_thrust*NEWTON_LBF));

这是最终结果: http://www.lib.aero /hosted/motors/cesaroni_12-15-12.html (下面的示例图)

Here's the end result: http://www.lib.aero/hosted/motors/cesaroni_12-15-12.html (sample graph below)

推荐答案

在我看来,最简单的方法是简单地缩放数据:

It seems to me that the easiest way to do this is to simply scale the data:

set y2tics
plot sin(x) w lines, 5*sin(x) w lines axes x1y2

当然,您是从文件中绘制数据,因此看起来更像是:

Of course, you're plotting data from a file, so it would look something more like:

set y2tics
FACTOR=0.2248  #conversion factor from newtons to lbf
plot 'datafile' u 1:2 w lines, '' u 1:(FACTOR*$2) w lines

如果要显式设置yrange(可能需要这样做):

If you're setting the yrange explicitly (which you may need to do):

set yrange [ymin:ymax]
set y2range [ymin*FACTOR:ymax*FACTOR]


最后,如果您真的想依靠自动缩放,则需要做一些体操".


Finally, if you really want to rely on autoscaling, you're going to need to do some "gymnastics".

首先,设置一个虚拟端子,这样我们就可以plot而无需绘制图:

First, set a dummy terminal so we can plot without making a plot:

set term unknown
plot 'datafile' u 1:2  #collect information on our data

现在我们已经收集了有关数据的信息,我们可以设置真实的y2range

Now that we've collected information on the data, we can set our real y2range

FACTOR=0.2248
set y2range [FACTOR*GPVAL_Y_MIN : FACTOR*GPVAL_Y_MAX]
set y2tics nomirror
set ytics nomirror

现在设置终端并绘制数据:

Now set the terminal and plot the data:

set term ...
set output ...
plot 'datafile' u 1:2 w lines

这篇关于gnuplot:如何为不同单位添加y2轴比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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