有没有一种方法可以使用gnuplot在一个图形上使用3个不同的Y轴?

问题描述

我正在使用带有天气API的GNUplot制作天气显示图。我目前正在计划未来48小时的温度和降雨量。

enter image description here

如上图所示,温度是在左侧定义的轴的线。条形图(左下图)描绘了降雨,右图则定义了降雨轴。 (0,0.5,1)。

但是,我也想在图中包含其他数据。我要包括的第一件事是图表顶部的云量。再次作为条形图。

包括一个图形编辑器是一个样机:

enter image description here

是否可以使用gnuplot做到这一点,还是我必须使用其他程序来完成它?

解决方法

您的y1轴位于左侧,y2轴位于右侧。如果您想拥有第3个y轴,则必须以某种方式进行移动。一种实现此目的的方法是使用multiplot,基本上是几个图相互重叠。 您必须确保所有绘图在画布上使用相同的(固定)边距(自动装订功能可能无法使用)和相同的xrange(第二个绘图从第一个绘图中获取)。请检查以下示例,获取一些随机数据。当然,可以进行一些微调。使其适应您的需求。

代码:

### Three y-axes
reset session

# create some test data
myTimeFmt = "%d.%m.%Y %H:%M:%S"
set print $Data
    do for [i=1:48] {
        myTime(i) = strftime(myTimeFmt,time(0)+i*3600)
        myTemp(i) = sin(i/5.)*5 + 20 + rand(0)
        myRain(i) = int(rand(0)+0.3) * rand(0)*20
        myCloud(i) = rand(0)*50
        print sprintf("%s %g %g %g",myTime(i),myTemp(i),myRain(i),myCloud(i))
    }
set print

set key off
set margins screen 0.1,screen 0.8,screen 0.1,screen 0.94

set multiplot
    set format x "%H:%M" timedate
    set xtics 3600*6
    set grid xtics,mxtics,ytics,mytics
    
    ##### first plot
    set ylabel "Temperature °C" tc "red"
    set yrange[10:30]
    set ytics nomirror tc "red"

    set y2label "Rain / mm" offset -1,0 textcolor rgb "blue"
    set y2range[0:40]
    set y2tics nomirror tc "blue"

    set style fill solid 1.0 
    plot $Data u (timecolumn(1,myTimeFmt)):3 axes x1y1 w l lc "red",\
        '' using (timecolumn(1,myTimeFmt)):4 axes x1y2 w boxes lc "blue"

    unset xlabel 
    unset ylabel
    unset y2label
    unset tics

    ##### Second plot
    set bmargin screen 0.73
    set border 4
    set xrange[GPVAL_X_MIN:GPVAL_X_MAX]    # identical xrange like 1st plot
    set y2range[100:0] reverse
    plot $Data u (timecolumn(1,myTimeFmt)):5 axes x1y2 w boxes lc rgbcolor "grey"

    ##### Third plot (just for 3rd y-axis)
    set rmargin at screen 0.9
    set border 8     # only right border visible
    set y2label "Cloud coverage" offset -1,0 textcolor rgb "black"
    set y2tics nomirror offset 0,0
    plot NaN    # plot some dummy

unset multiplot
### end of code

结果:

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...