Gnuplot: how to add y2 axis scale for different units

前端 未结 3 1348
别跟我提以往
别跟我提以往 2020-12-14 03:51

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.

The file represents r

3条回答
  •  眼角桃花
    2020-12-14 04:42

    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
    

    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".

    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
    

    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
    

提交回复
热议问题