Gnuplot 不同缩放y轴之间的填充曲线

Gnuplot 不同缩放y轴之间的填充曲线,gnuplot,Gnuplot,我必须“重新设计”一个图表,如下所示: 0 0 11 50 1 J 10 70 2 F 11 42 3 M 12 50 4 A 15 50 5 M 18 20 6 J 22 10 7 J 25 1 8 A 25 20 9 S 23 40 10 O 20 80 11 N 25 70 12 D 11 60 我的问题是,如果使用不同的缩放y轴,“Filled Curves”选项无法正常工作 set y2tics textcolor rgb "bl

我必须“重新设计”一个图表,如下所示:

0 0 11 50  
1 J 10 70  
2 F 11 42  
3 M 12 50  
4 A 15 50  
5 M 18 20  
6 J 22 10  
7 J 25 1  
8 A 25 20  
9 S 23 40  
10 O 20 80  
11 N 25 70  
12 D 11 60  

我的问题是,如果使用不同的缩放y轴,“Filled Curves”选项无法正常工作

set y2tics textcolor rgb "black" 
set ytics nomirror
set yrange [0:80]
set y2range [0:180]
set key off
set grid dashtype 5 # auch dt ".-." möglich
plot "klima_flach.txt" using 1:3:4 with filledcurves x1,\
     "" using 1:4 with lines axis x1y2,\
     "" using 1:3:xtic(2) with lines axis x1y1
使用的数据如下所示:

0 0 11 50  
1 J 10 70  
2 F 11 42  
3 M 12 50  
4 A 15 50  
5 M 18 20  
6 J 22 10  
7 J 25 1  
8 A 25 20  
9 S 23 40  
10 O 20 80  
11 N 25 70  
12 D 11 60  
有什么想法吗?我怎样才能解决这个问题


顺便说一句:如原始图表中的模式。。。是否可能?

填充曲线没有为第二列和第三列中的y值选择不同轴的选项。但幸运的是,你有固定的y范围。因此,您可以为其中一列定义缩放函数:

set y2tics textcolor rgb "black" 
set ytics nomirror
set yrange [0:80]
set y2range [0:180]
scale = 80.0/180.0
set key off
set grid dashtype 5 # auch dt ".-." möglich
plot "klima_flach.txt" using 1:3:(scale*$4) with filledcurves,\
     "" using 1:4 with lines axis x1y2,\
     "" using 1:3:xtic(2) with lines axis x1y1

@沃尔夫冈·霍费尔(Wolfgang Höfer),在这类沃尔特/利思气候图中,轴之间的比例为2。因此,y范围应为[0:90],因此比例因子应为90./180。 然而,我认为@Christoph的回答解决了你的问题

关于最后一个问题:图片中的图案,即垂直填充图案?这就是我最近在这里问的问题。显然,这在gnuplot中似乎是不可能的

不久前,我还“挣扎”于气候图,即填充曲线,甚至非线性轴。我想提供的代码,我结束了。也许用gnuplot绘制这样的气候图对你或其他人都有用。如果您正在读取文件,请用文件名替换
$DataIn
。欢迎提出建议和改进

# Walter/Lieth climate diagram with nonlinear axis
reset session
set encoding "utf8"

$DataIn <<EOD
# Mumbai/India, 18°54'N/72°49'E, 11 m
# No. Month Temperature Precipitation
1 January 23.9 3
2 February 23.9 3
3 March 26.1 3
4 April 28.1 2
5 May 29.7 18
6 June 28.9 485
7 July 27.2 617
8 August 27.0 340
9 September 27.0 264
10 October 28.1 64
11 November 27.2 13
12 December 25.6 3
EOD

# in order to be flexible for different input files 
ColTemp = 3     # col# temperature
ColPrec = 4     # col# precipitation

# get location label from first commented row starting after '# '
set datafile commentschar ""   # set the comment char to none
set datafile separator "\n"    # data will be a full line
set table $Dummy               # plot following data to a dummy table
    # plots only first line 'every ::0::0' as string to the dummy table
    # and assigns this line starting after the 3rd character to variable 'Location'
    plot $DataIn u (Location = stringcolumn(1)[3:]) every ::0::0 with table
unset table                    # stop plotting to table
set datafile commentschar "#"       # restore default commentschar
set datafile separator whitespace   # restore default separator
set label 1 at graph 0.02,0.96 Location font ",10"    # put label on graph

# set periodic boundaries, i.e. add lines of Dec and Jan again
# independent of the input format $DataIn, column1 of $Data will be the number of month
set datafile separator "\n"
set table $Data
    plot $DataIn u (0):(stringcolumn(1)) every ::11::11 with table
    plot $DataIn u ($0+1):(stringcolumn(1)) with table
    plot $DataIn u (13):(stringcolumn(1)) every ::0::0 with table
unset table
set datafile separator whitespace
# print $Data

# settings for nonlinear scale
ScaleChangeAt = 100.
ScaleChangeFactor = 5.
f1(y) = (y<=ScaleChangeAt) ? y : ((y - ScaleChangeAt)/ScaleChangeFactor + ScaleChangeAt)
f2(y) = (y<=ScaleChangeAt) ? y : ((y - ScaleChangeAt)*ScaleChangeFactor + ScaleChangeAt)
f3(y) = f1(y)/2.   # relation between axes y and y2; standard for Walter/Lieth climate diagrams
set nonlinear y2 via f1(y) inverse f2(y)


# settings for x-axis
set xrange[0.5:12.5]
set xtics 1 scale 0,1
set mxtics 2
set grid mxtics
# create months labels from local settings 
do for [i=1:12] {
    set xtics add (strftime("%b",strptime("%m",sprintf("%g",i))) i) 
}

# settings for y- and y2-axes
stats [*:*] $DataIn u ColTemp:ColPrec nooutput
Round(m,n) = int(m/n)*n + sgn(m)*n
Ymin = STATS_min_x > 0 ? 0 : Round(STATS_min_x,10)
Ymax = 50
Y2min = Ymin < 0 ? f1(Ymin)*2 : 0
Y2max = Round(STATS_max_y,10**int(log(STATS_max_y)/log(10))) # round to next 10 or 100
# print Ymin, Ymax, Y2min, Y2max

# y-axis
set ylabel "Temperature / °C" tc rgb "red"
set yrange [Ymin:f3(Y2max)]  # h(Y2max)]
set ytics 10 nomirror tc rgb "red"
# "manual" setting of ytics, up to 50°C
set ytics ("0" 0)
do for [i=Ymin:50:10] {
    set ytics add (sprintf("%g",i) i)
}

# settings for y2-axis
set y2label "Precipitation / mm" tc rgb "blue"
set y2range [Y2min:Y2max]
# "manual" setting of y2tics
set y2tics nomirror tc rgb "blue"
set y2tics ("0" 0)
set grid y2tics
do for [i=20:ScaleChangeAt:20] {
    set y2tics add (sprintf("%g",i) i)
}
do for [i=ScaleChangeAt:Y2max:20*ScaleChangeFactor] {
    set y2tics add (sprintf("%g",i) i)
}

plot \
    $Data u 1:ColTemp+1:(f3(column(ColPrec+1))) axis x1y1 w filledcurves above lc rgb "yellow" not,\
    '' u 1:ColTemp+1:(f3(column(ColPrec+1))) axis x1y1 w filledcurves below fs pattern 4 fc rgb "blue" not,\
    '' u 1:(f3(ScaleChangeAt)):(f3(column(ColPrec+1))) axis x1y1 w filledcurves below fs solid 1.0 fc rgb "blue" not,\
    '' u 1:ColTemp+1 w l lw 2 lc rgb "red" not,\
    '' u 1:ColPrec+1 axes x1y2 w l lw 2 lc rgb "blue" not
### end of code
具有非线性轴的Walter/Lieth气候图 重置会话 设置编码“utf8”
$DataIn好的,谢谢。对我来说很清楚,但向其他人解释却不那么容易:)(excel用户:()很好,谢谢……但要理解每一行还有很长的路要走:)不客气。如果某些行需要更多或特殊解释,请告诉我。。。正如我所说的,可能还有改进或简化的余地。这是从评论中获取内容的一种很好的方法,但我对部分绘图$DataIn u(Location=stringcolumn(1)[3:],$1]有一个问题。。。。确定-创建变量“Location”,并将第一个stringcolumn的字符3-*分配给ist。括号中的是ok,因为您不直接寻址列。但是括号内的$1呢?它将从第三个字符开始的第一行分配给变量
位置
。实际上,您不需要
$1
。以下操作也有效:
在u(Location=stringcolumn(1)[3:])中绘制$dataevery::0::0和表
。为代码添加了解释。谢谢!但另一个问题是:将分隔符从空白改为\n。对我来说,这意味着文件中的每一行都成为一列。然后,文件的内容是一个包含许多列的长行。但在本例中::11::11毫无意义——但它是有效的。这意味着,我错了——在哪里,为什么?