如何在gnuplot中获取X和Y范围之间的关系

问题描述 投票:0回答:1

我正在使用这样的圆圈绘制数据:

$DATA<<EOD
1.0000,"CAN",80.6600,1.6700,0.2879,
2.0000,"DEU",79.8400,1.3600,0.4134,
3.0000,"DNK",78.6000,1.8400,0.2144,
4.0000,"EGY",72.7300,2.7800,0.4077,
5.0000,"GBR",80.0500,2.0000,0.3610,
6.0000,"IRN",72.4900,1.7000,0.3906,
7.0000,"IRQ",68.0900,4.7700,0.2810,
8.0000,"ISR",81.5500,2.9600,0.2195,
9.0000,"RUS",68.6000,1.5400,0.5696,
10.0000,"USA",78.0000,2.0000,1.0000,
EOD
set datafile separator comma
set style data circles
set term windows
unset xtics; unset ytics; unset x2tics; unset y2tics
set grid xtics layerdefault
set grid ytics layerdefault
set xtics nomirror
set ytics nomirror
set border 3.00000
set colorsequence classic
set title "This is My Title"
set xlabel "Cities"
set ylabel "Population (in Millions)"
set key default
set style fill solid 4.00 transparent
plot $DATA every ::0::0 using ($3):($4):($5) title "CAN",\
$DATA every ::1::1 using ($3):($4):($5) title "DEU",\
$DATA every ::2::2 using ($3):($4):($5) title "DNK",\
$DATA every ::3::3 using ($3):($4):($5) title "EGY",\
$DATA every ::4::4 using ($3):($4):($5) title "GBR",\
$DATA every ::5::5 using ($3):($4):($5) title "IRN",\
$DATA every ::6::6 using ($3):($4):($5) title "IRQ",\
$DATA every ::7::7 using ($3):($4):($5) title "ISR",\
$DATA every ::8::8 using ($3):($4):($5) title "RUS",\
$DATA every ::9::9 using ($3):($4):($5) title "USA",\
$DATA every ::9::9 using ($3):($4)+($5):($2) with labels center notitle,\
$DATA every ::9::9 using ($3)-($5):($4):($2) with labels center notitle,\
$DATA every ::9::9 using ($3):($4)-($5)/2+0.1:($2) with labels center notitle

在最后三行中,我尝试将标签放置在圆圈的上方、左侧和下方。

将标签放置在圆的左侧(或右侧)不是问题,因为圆的半径与 x 平面的比例相匹配。这样就可以了。

将标签定位在圆的顶部效果不一样,因为 y 尺度与 x 平面不同。

可以将标签定位在圆圈底部,但需要一些计算,添加的除以 2 并加 0.1 的逻辑适用于美国条目,但对于较小的数据点则失败。

我的问题是:有没有办法获得 X 和 Y 平面之间的关系\比例,以便我可以计算顶部\底部标签的偏移量? (除了发出 show x\yrange 命令并读回输出)

我尝试了“set view equal xy”命令,但它没有改变任何内容,并且“show size”命令显示当前比例为 1,1。

谢谢你 罗伯托

gnuplot scale
1个回答
2
投票

您可以访问名为

GPVAL_X_MIN
等的变量。所以你可以使用:

charsize=1.5
LEN=3
ratio=1

plot '012_d.dat' every ::9::9 using 3:4:5 w circles title "USA",\
'' every ::9::9 using 3:($4+ratio*$5):2 with labels center offset 0,charsize notitle,\
'' every ::9::9 using ($3-$5):4:2 with labels center offset -LEN,0 notitle,\
'' every ::9::9 using 3:($4-ratio*$5):2 with labels center offset 0,-charsize notitle

ratio=(GPVAL_Y_MAX-GPVAL_Y_MIN)/(GPVAL_X_MAX-GPVAL_X_MIN)

replot

解决方案的关键点(和向后)是

GPVAL_X_MIN
(和其他)在绘图后具有正确的值,因此您必须使用
replot

注意事项

  1. 如果您不转换列的值,则不必使用“$”,例如。

    using ($3):($4):($5)
    等于
    using 3:4:5

  2. 如果您在

    plot
    命令中再次使用数据(文件),则不必再次写入(文件)名称:
    ''

编辑

  1. 正如您所说,您可以(必须)微调解决方案:在

    using 3:($4+ratio*$5):2
    中,您可以使用常数乘数;您可以更改(减少)charsize。在这种情况下,标签的偏移将更加依赖于数据。

  2. 正如@theozh所说,您可以使用循环来压缩代码。然而,正如我一开始所想的那样,这更棘手:

首先想到,你必须使用类似的东西:

plot for[i=0:9] '012_d.dat' every ::i::i using 3:4:5 title $2

但是,这不会产生任何密钥。我的第二个想法是:

plot for[i=0:9] '012_d.dat' every ::i::i using 3:4:5 title sprintf("%s",$2)
         f_sprintf: attempt to print numeric value with string format

如您所见,这并没有更好。搜索

help plot title

语法: 标题 < text> |无标题 [< ignored text>] 标题列标题 |标题栏标题(N) {在{开始|结束}} {{无}增强}

其中 < text> 是带引号的字符串或计算结果为 细绳。引号不会显示在键中。注意:开始于 gnuplot 版本 5.4,如果 < text> 是表达式或函数 it it 在绘制相应的函数或数据流后进行评估。 这允许标题引用计算或输入的数量 在绘图期间,这在早期的 gnuplot 版本中是不可能的。

我在

using
部分发现了一个假作业:

plot for[i=0:9] '012_d.dat' every ::i::i using ((x=stringcolumn(2)) eq "XXX"?1/0:$3):4:5 title sprintf("%s",x)

这已经起作用了:)与

plot
的其他部分:

plot for[i=0:9] '012_d.dat' every ::i::i using ((x=stringcolumn(2)) eq "XXX"?1/0:$3):4:5 title sprintf("%s",x),\
 for[i=0:9] '' every ::i::i using 3:($4+ratio*$5):2 with labels center offset 0,charsize notitle,\
 for[i=0:9] '' every ::i::i using ($3-$5):4:2 with labels center offset -LEN,0 notitle,\
 for[i=0:9] '' every ::i::i using 3:($4-ratio*$5):2 with labels center offset 0,-charsize notitle

© www.soinside.com 2019 - 2024. All rights reserved.