gnuplot安装(202203)


使用ns3时需要用到gnuplot

gnuplot aa
rm aa

安装与使用

以下操作在su下进行,make install时否则会有权限错误

下载

wget https://nchc.dl.sourceforge.net/project/gnuplot/gnuplot/5.0.5/gnuplot-5.0.5.tar.gz

解压

tar -zxvf gnuplot-5.0.5.tar.gz

配置安装路径

cd gnuplot-5.0.5

./configure --prefix=/usr/local/gnuplot

编译

make

安装

make install

配置编译环境

在/etc/profile.d下创建gnuplot.sh

vim /etc/profile.d/gnuplot.sh

写入内容

export GNUPLOT=/usr/local/gnuplot
export PATH=/usr/local/gnuplot/bin:$PATH
export MANPATH=/usr/local/gnuplot/share/man/man1:$MANPATH

启用环境

source /etc/profile.d/gnuplot.sh

安装成功

在这里插入图片描述

常见错误

error:terminal type set to 'unknown'

解决

安装gnuplot-x11

apt-get install gnuplot-x11

在home下新建.octaverc,内容如下

setenv("GNUTERM","X11")

重启

参考

https://www.jianshu.com/p/8087e2fd7835

https://blog.csdn.net/lx_ros/article/details/74296181

gnuplot-tutorial-part

该tutorial适用版本-version 4.2

其他阅读

http://www.gnuplot.info/documentation.html Official gnuplot documentation

http://ouc.ai/zhenghaiyong/courses/tutorials/gnuplot/gnuplot-zh.pdf 使用 gnuplot 科学作图 Gnuplot 中文教程∗

安装

函数

通常,可以绘制 C、FORTRAN、Pascal 或 BASIC 接受的任何数学表达式。运算符的优先级由 C 编程语言的规范决定。

支持的功能包括:(变量名 x、y 和 z 用作默认自变量。)

      __________________________________________________________
      函数返回
      ------------ ------------------------------------ ------ 
      abs(x) x 的绝对值,|x| 
      acos(x) x 的反余弦
      asin(x) x 的反正弦  
      atan(x) x 的反正切
      cos(x) x 的余弦,x 的单位是弧度。
      cosh(x) x 的双曲余弦,x 为弧度
      erf(x) x 的误差函数
      exp(x) x 的指数函数,底数为 e 
      inverf(x) x 的逆误差函数
      invnorm(x) x 的逆正态分布
      log(x) log of x, base e 
      log10(x) log of x, base 10 
      norm(x) 正态高斯分布函数
      rand(x) 伪随机数生成器      
      sgn(x) 1 if x > 0, -1 if x < 0, 0 如果 x=0 
      sin(x) x 的正弦,x 的弧度
      sinh(x) x 的双曲正弦,x 的弧度
      sqrt(x) x 的平方根
      tan(x) x 的正切, x 是弧度
      tanh(x) x 的双曲正切,x 是弧度
      ___________________________________________________________ 
      Bessel、gamma、ibeta、igamma 和 lgamma 函数也是
      支持的。许多函数可以接受复杂的参数。
      还支持二元和一元运算符。  

Gnuplot 中支持的运算符与 C 编程语言中相应的运算符相同,除了大多数运算符接受整数、实数和复数参数。在 FORTRAN 中支持 ** 运算符(求幂)。括号可用于更改评估顺序。

plotsplot 是 Gnuplot 中的主要命令。他们以多种方式绘制函数和数据。

plot 用于绘制 2-d 函数和数据,

splot绘制 3-d 表面和数据。

语法:
       plot {[ranges]} 
            {[function] | {"[datafile]" {datafile-modifiers}}} 
            {axes [axes] } { [title-spec] } {with [style] } 
            {, {definitions,} [function] ...}

其中提供了 [function] 或用引号括起来的数据文件的名称。

plot {<ranges>} <plot-element> {, <plot-element>, <plot-element>}

Each plot element consists of a definition, a function, or a data source
 together with optional properties or modifiers:
       plot-element:
            {<iteration>}
            <definition> | {sampling-range} <function> | <data source>
                         | keyentry
            {axes <axes>} {<title-spec>}
            {with <style>}

Plot && Splot

Plotting Functions

要绘制函数,只需在 gnuplot> 提示符下键入:plot [function]。

例如,尝试:

      gnuplot> plot sin(x)/x    
      gnuplot> splot sin(x*y/20) 
      gnuplot> plot sin(x) title 'Sine Function', tan(x) title 'Tangent'

Plotting Data

文件中包含的离散数据可以通过在绘图或split命令行中指定数据文件的名称(用引号括起来)来显示。

  • 数据文件中的数据应以数字列的形式排列。各列之间应只用空白处(制表符或空格)隔开(没有逗号)。
  • 以#字符开头的行被视为注释,并被Gnuplot所忽略。
  • 数据文件中的空白行会导致连接数据点的线断开。

下图为可以示例文件

      # 这个文件叫做 force.dat 
      # Force-Deflection data for a beam and a bar 
      # Deflection Col-Force Beam-Force 
      0.000 0 0     
      0.001 104 51 
      0.002 202 101 
      0.003 298 148 
      0.0031 290 149 
      0.004 
      289 201 
      0.0041 2910205 250 
      0.010 311 260 
      0.020 280 240

可以通过键入以下内容来显示您的数据:

      gnuplot> 使用 1:2 标题“列”绘制“force.dat”,\ 
                      “force.dat”使用 1:3 标题“梁”

不要在行继续符 “” 之后键入空格。

您的数据可能位于多个数据文件中。

      gnuplot>  plot  "fileA.dat" using 1:2 title 'data A', \
                      "fileB.dat" using 1:3 title 'data B'

自定义PLOT

绘图上可以自定义许多项目,例如轴的范围、x 和 y 轴的标签、数据点的样式、连接数据点的线的样式以及整个绘图的标题。

plot自定义

Plots may be displayed in one of eight styles: lines, points, linespoints, impulses, dots, steps, fsteps, histeps, errorbars, xerrorbars, yerrorbars, xyerrorbars, boxes, boxerrorbars, boxxyerrorbars, financebars, candlesticks or vector

指定线/点样式(line/point style)使用plot 命令如下:

      gnuplot> plot "force.dat" using 1:2 title 'Column' with lines, \ 
                    "force.dat" u 1:3 t 'Beam' wlinespoints

请注意: using 、 title 和 with 可以缩写为: u 、 t 和 w 。

此外,每个线和点样式都有一个关联的编号。

使用set自定义

使用 set 命令指定轴范围、轴标签和绘图标题以及许多其他功能的自定义

set 命令的具体示例如下。(这些示例中使用的数值是任意的。)

      Create a title:                  > set title "Force-Deflection Data" 
      Put a label on the x-axis:       > set xlabel "Deflection (meters)"
      Put a label on the y-axis:       > set ylabel "Force (kN)"
      Change the x-axis range:         > set xrange [0.001:0.005]
      Change the y-axis range:         > set yrange [20:500]
      Have Gnuplot determine ranges:   > set autoscale
      Move the key:                    > set key 0.01,100
      Delete the key:                  > unset key
      Put a label on the plot:         > set label "yield point" at 0.003, 260 
      Remove all labels:               > unset label
      Plot using log-axes:             > set logscale
      Plot using log-axes on y-axis:   > unset logscale; set logscale y 
      Change the tic-marks:            > set xtics (0.002,0.004,0.006,0.008)
      Return to the default tics:      > unset xtics; set xtics auto

可以使用 set 命令自定义的其他功能包括:箭头、边框、剪辑、轮廓、网格、映射、极坐标、表面、时间、视图等等。


用其他注释字符绘制数据文件

如果您的数据文件有 # 以外的注释字符,您可以告诉 Gnuplot。

例如,如果您的数据文件有“%”注释字符(为了 Matlab 兼容性),键入

  gnuplot>  set datafile commentschars "#%"

表示“#”或“%”字符开始注释。

GNUPLOT SCRIPTS

为了简化您的绘图操作,可以将几个 Gnuplot 命令组合到一个脚本文件中

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐