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

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

  • 相关阅读:
    出现 could not open jvm.cfg 的解决办法
    powerdesigner相关概念理解
    UML建模类图
    LAMP环境折腾
    ThinkPHP学习笔记1
    ubuntu14在kDE界面下的关于eclipse提示框黑色背景的修改!
    LAMP环境安装与apache配置
    Unix网络编程---第四次作业
    Unix网络编程---第三次作业
    Unix网络编程---第二次作业
  • 原文地址:https://www.cnblogs.com/jingjingblog/p/8664393.html
Copyright © 2011-2022 走看看