时间:2010-07-23 12:44:19

标签: gnuplot

6 个答案:

答案 0 :(得分:35)

答案 1 :(得分:19)

Gnuplot 5.0.1 datablocks

main.gnuplot

$data << EOD
1 1
2 4
3 9
4 16
EOD

plot "$data" \
  with linespoints \
  title "my data"

转换为PNG:

gnuplot -e 'set terminal png' -e 'set output "main.png"' main.gnuplot

输出:

enter image description here

此方法比'-'更通用,因为它可以更轻松地多次重复使用相同的数据,包括在同一plot命令上:https://stackoverflow.com/a/33064402/895245

版本5在Ubuntu 15.04上可用,或者从源代码编译:https://askubuntu.com/a/684136/52975

使用函数绘图时,您可能还对+++特殊文件名感兴趣。

在Ubuntu 18.10上测试,gnuplot 5.2。

答案 2 :(得分:3)

使用带管道的shell的示例

gnuplot -p <(echo -e 'plot "-"\n1 1\ne')

答案 3 :(得分:1)

一行ping图与gnuplot

抱歉,它不轻(361个字符):

gnuplot -p -e "set xdata time;set timefmt '%s';set xrange [ '$(date +%s)' : '$(date -d 'now +30 seconds' +%s)' ];plot '-' using 1:2 with line title 'ping google';" < <(( ping -c 30 -n google.com| sed -u 's/^64.*time=\([0-9.]\+\) .*$/\1/p;d' | tee >(sed -u 's/.*/now/'| stdbuf -oL date -f - +d%s)) | sed -u 'N;s/\n/ /;s/\([0-9.]\+\) d\([0-9]\+\) */\2 \1/;s/d//')

运行此行将使您的终端保持30秒,而不是在屏幕上显示最近30秒内向 google.com 发送ping延迟的图表。

同样的行可以像这样拆分(也可以):

gnuplot -p -e "
    set xdata time;
    set timefmt '%s';
    set xrange [ '$(
        date +%s
      )' : '$(
        date -d 'now +30 seconds' +%s
      )' ];
    plot '-' using 1:2 with line title 'ping google';
    " < <((
    ping -c 30 -n google.com |
        sed -u 's/^64.*time=\([0-9.]\+\) .*$/\1/p;d' |
        tee >(sed -u 's/.*/now/'| stdbuf -oL date -f - +d%s)) |
    sed -u 'N;s/\n/ /;s/\([0-9.]\+\) d\([0-9]\+\) */\2 \1/;s/d//'
)

但这不打印价值!

所以我添加了几个字节:

gnuplot -p -e "set xdata time;set timefmt '%s';set xrange [ '$(date +%s)' : '$(date -d 'now +30 seconds' +%s)' ];plot '-' using 1:2 with line title 'ping google';" < <(( ping -c 30 -n google.com| sed -u 's/^64.*time=\([0-9.]\+\) .*$/\1/p;d' | tee >(sed -u 's/.*/now/'| stdbuf -oL date -f - +d%s)  ) | sed -u 'N;s/\n/ /;s/\([0-9.]\+\) d\([0-9]\+\) */\2 \1/;s/d//' | tee >(printf "%(%T)T %s\n" $(</dev/stdin) | column -c $COLUMNS >&2 ))

这可能会创建一个这样的窗口:

enter image description here

同时在终端上打印:

17:58:53 19.6   17:59:00 124    17:59:07 159    17:59:13 194    17:59:19 17.1
17:58:54 18.7   17:59:02 19.4   17:59:08 20.3   17:59:14 16.8   17:59:20 20.0
17:58:55 17.9   17:59:03 180    17:59:09 76.4   17:59:15 48.9   17:59:21 192
17:58:57 115    17:59:04 186    17:59:10 226    17:59:16 221    17:59:22 17.1
17:58:58 18.5   17:59:05 16.8   17:59:11 109    17:59:17 19.0
17:58:59 17.0   17:59:06 184    17:59:12 18.8   17:59:18 18.7

重写分裂:

gnuplot -p -e "
    set xdata time;
    set timefmt '%s';
    set xrange [ '$(date +%s)' : '$(date -d 'now +30 seconds' +%s)' ];
    plot '-' using 1:2 with line title 'ping google';" < <(
  (
      ping -c 30 -n google.com |
        sed -u 's/^64.*time=\([0-9.]\+\) .*$/\1/p;d' |
        tee >(sed -u 's/.*/now/'| stdbuf -oL date -f - +d%s)
  ) | sed -u 'N;s/\n/ /;s/\([0-9.]\+\) d\([0-9]\+\) */\2 \1/;s/d//' |
  tee >(printf "%(%T)T %s\n" $(</dev/stdin) |
  column -c $COLUMNS >&2 )
)

答案 4 :(得分:0)

解决方案使用数组和参数线。

X="0.1 0.2 0.3 0.4 0.5"
Y="-1  0   2   4   8"

set parametric
set trange [1:words(X)]; set samples words(X)
plot (0+word(X,int(t))),(0+word(Y,int(t))) 

output

来源:https://groups.google.com/d/msg/comp.graphics.apps.gnuplot/UdiiC2cBQNo/xEyj6i7Y910J

答案 5 :(得分:0)

10年后...

您可以直接在gnuplot中编写如下内容:

plot "< ./format.sh '{(1,5),(2,10),(3,1)}'"

其中format.sh是本地文件中的一个非常简单的脚本(记住要赋予它exec权限):

#!/bin/bash
echo "$1" | sed 's:^..\(.*\)..$:\1:' | sed 's:),(:\n:g' | sed 's:,: :g'

它如何工作?

三个sed命令执行以下操作:

  1. 分别删除前两个字符{(})
  2. 将序列),(更改为换行符
  3. 将剩余的,更改为空格

所以:

$ ./format.sh '{(1,5),(2,10),(3,1)}'
1 5
2 10
3 1

popen上的gnuplot plot "< command"语法杠杆可在外壳中运行command,捕获输出并即时绘制输出。在其他情况下,它也可能非常有用。

相关问题