gnuplot:如何用splot绘制断开的线?

时间:2019-04-04 16:26:43

标签: gnuplot

这不是How to draw distinct line segments in gnuplot using splot的重复项。 问题稍有不同,但是我也想用splot绘制断开的线。上面的链接说,您必须在数据中引入2个空行。这就是创建$Data1时的工作。

问题:为什么$Data1已连接但$Data2已断开连接?我也想断开$Data1的连接。怎么了?有任何想法吗?错误或功能?

编辑:

@Ethan的回答基本上导致线路断开。但是,仍然存在一些不一致之处。创建数据文件Data3.dat时,仅打印一个\n来创建数据文件就足够了,但是在文件中看到两个\n。为什么?我很困惑。

代码:

### splot disconnected lines
reset session
set border 0
unset tics

set print $Data1
do for [i=1:3] {
    print sprintf("%.3f %.3f %.3f",rand(0),rand(0),rand(0))
    print sprintf("%.3f %.3f %.3f",rand(0),rand(0),rand(0))
    print "\n"; # print ""
}
set print

$Data2 <<EOD
0.266 0.838 0.173
0.413 0.985 0.102


0.173 0.879 0.478
0.375 0.748 0.659


0.605 0.365 0.966
0.001 0.426 0.129
EOD

FILE = "Data3.dat" 
set print FILE
do for [i=1:3] {
    print sprintf("%.3f %.3f %.3f",rand(0),rand(0),rand(0))
    print sprintf("%.3f %.3f %.3f",rand(0),rand(0),rand(0))
    print "\n"
}
set print


splot \
    $Data1 u 1:2:3 w lp pt 7 lc rgb "red" t "Why is $Data1 connected?", \
    $Data2 u 1:2:3 w lp pt 7 lc rgb "web-green" t "$Data2 disconnected", \
    FILE   u 1:2:3 w lp pt 7 lc rgb "blue" t 'Why is FILE with just one "\\n" disconnected'
### end of code

结果:$Data1

0.949 0.287 0.592
0.547 0.876 0.294


0.468 0.930 0.703
0.294 0.990 0.919


0.038 0.550 0.467
0.222 0.390 0.941

图:

enter image description here

3 个答案:

答案 0 :(得分:2)

您仅在$ data1中的数据块之间创建一个空白行,而不是两个空白行

set print $Data1
do for [i=1:3] {
    print sprintf("%.3f %.3f %.3f",rand(0),rand(0),rand(0))
    print sprintf("%.3f %.3f %.3f",rand(0),rand(0),rand(0))
    print "\n"
    print "\n"   # 2 blank lines required
}
set print

答案 1 :(得分:0)

版本5.2.6

gnuplot> set print $D; print ""
gnuplot> set print $E; print "\n"
gnuplot> set print $F; print "\n\n"
gnuplot> set print $G; print "\n\nX"
gnuplot> show var $

        Variables beginning with $:
        $D = <1 line data block>
        $E = <1 line data block>
        $F = <1 line data block>
        $G = <1 line data block>

5.3版

gnuplot> set print $D; print ""
gnuplot> set print $E; print "\n"
gnuplot> set print $F; print "\n\n"
gnuplot> set print $G; print "\n\nX"
gnuplot> show var $

        Variables beginning with $:
        $D = <1 line data block>
        $E = <1 line data block>
        $F = <2 line data block>
        $G = <3 line data block>

答案 2 :(得分:0)

问题实际上不是关于splot,而是: 我可以得到多少行?

总结我从@Ethan的评论和答案中所了解的内容,

一些测试代码:

### How many empty lines do I get?
reset session

set print $Data1; print "1 Dataline"; print "";      print "2 Dataline";
set print $Data2; print "1 Dataline"; print "\n";    print "2 Dataline";
set print $Data3; print "1 Dataline"; print "\n\n";  print "2 Dataline";
set print $Data4; print "1 Dataline"; print "\n\nX"; print "2 Dataline";

set print "Data1.txt"; print "1 Dataline"; print "";      print "2 Dataline";
set print "Data2.txt"; print "1 Dataline"; print "\n";    print "2 Dataline";
set print "Data3.txt"; print "1 Dataline"; print "\n\n";  print "2 Dataline";
set print "Data4.txt"; print "1 Dataline"; print "\n\nX"; print "2 Dataline";
set print    

print $Data1
print $Data2
print $Data3
print $Data4
### end of code

结果:

A = print to a datablock (how gnuplot handles the datablock)
B = print datablock to gnuplot console (how gnuplot displays the datablock)
C = print to datafile

Blank lines:
                  5.2          5.3
               A   B   C    A   B   C    
print ""       1   1   1    1   1?  1?
print "\n"     1   2   2    1   1?  1?
print "\n\n"   1   3   3    2   2?  2?
print "\n\nX"  1   2   2    2   2?  2?

我认为A,B,C栏应相同。好吧,它们不在5.2中(gnuplot内部行为与您看到的有所不同),这是我的实际“问题”。 由于我没有5.3,因此无法测试B和C,因此这些列只是猜测,如果我错了,请更正它们。我认为它们应该与A列相同。