zoukankan      html  css  js  c++  java
  • shell 调用 gnuplot 作图

    在ubuntu下使用gnuplot时,每画一个图需要在终端下数图多个命令,这样效率很低。

    我们知道shell脚本可以对命令进行批处理,于是就想到将这多个命令写到一个shell脚本中。

    首先,做了一下尝试:

    代码:文件名:testPlot.sh

    1 #!/bin/bash
    2 gnuplot
    3 
    4 set title "Node4 Local Clock"
    5 plot '/home/jing/m_allFile/project/SourceInsight-AS/AS/SourecinsightProject/AS-Source/ASRedundancy/ns-allinone-3.25/ns-3.25/nodeLocalTime4' with linespoints pt 7
    6 plot '' with linespoints pt 7

    其中,第一个 plot 后的是我的文件路径,因为这样就会将整个路径都输出到图中,所以会有第二个plot.

    在终端运行命令:1.先切到testPlot.sh所在目录

            2.运行命令:sh testPlot.sh

    之后,会进入到gnuplot命令中,然后输入  exit,报错

    testPlot.sh: 5: testPlot.sh: plot: not found
    testPlot.sh: 6: testPlot.sh: plot: not found

    最开始,认为是bash不支持gnuplot,然后换了好几个其他的shell,还是没有解决。

    最后,通过如下方式解决:

    代码:

    1 #!/bin/bash
    2 
    3 gnuplot -persist <<EOF
    4 
    5 set title "Node4 Local Clock"
    6 plot '/home/jing/m_allFile/project/SourceInsight-AS/AS/SourecinsightProject/AS-Source/ASRedundancy/ns-allinone-3.25/ns-3.25/nodeLocalTime4' with linespoints pt 7
    7 plot '' with linespoints pt 7
    8 
    9 EOF

    此代码可以画出正确的数据。

  • 相关阅读:
    J
    I
    uva122 二叉树的实现和层次遍历(bfs)
    A
    HDU 波峰
    2239: 童年的圣诞树
    1734: 堆(DFS)
    1731: 矩阵(前缀和)
    1733: 旋转图像(模拟)
    1728: 社交网络(概率问题 组合数/排列数)
  • 原文地址:https://www.cnblogs.com/jingjingblog/p/8664393.html
Copyright © 2011-2022 走看看