ns3--Making Plots using the Gnuplot Class

来源:互联网 发布:编程麻将机 编辑:程序博客网 时间:2024/06/06 02:01

原文链接:
https://www.nsnam.org/docs/manual/html/gnuplot.html

这里写图片描述
was created using the following code from gnuplot-example.cc:

using namespace std;string fileNameWithNoExtension = "plot-2d";string graphicsFileName        = fileNameWithNoExtension + ".png";string plotFileName            = fileNameWithNoExtension + ".plt";string plotTitle               = "2-D Plot";string dataTitle               = "2-D Data";// Instantiate the plot and set its title.Gnuplot plot (graphicsFileName);plot.SetTitle (plotTitle);// Make the graphics file, which the plot file will create when it// is used with Gnuplot, be a PNG file.plot.SetTerminal ("png");// Set the labels for each axis.plot.SetLegend ("X Values", "Y Values");// Set the range for the x axis.plot.AppendExtra ("set xrange [-6:+6]");// Instantiate the dataset, set its title, and make the points be// plotted along with connecting lines.Gnuplot2dDataset dataset;dataset.SetTitle (dataTitle);dataset.SetStyle (Gnuplot2dDataset::LINES_POINTS);double x;double y;// Create the 2-D dataset.for (x = -5.0; x <= +5.0; x += 1.0)  {    // Calculate the 2-D curve    //    //            2    //     y  =  x   .    //    y = x * x;    // Add this point.    dataset.Add (x, y);  }// Add the dataset to the plot.plot.AddDataset (dataset);// Open the plot file.ofstream plotFile (plotFileName.c_str());// Write the plot file.plot.GenerateOutput (plotFile);// Close the plot file.plotFile.close ();

示例代码:
src/stats/examples/gnuplot-example.cc
会产生这些文件:
plot-2d.plt
plot-2d-with-error-bars.plt
plot-3d.plt
要处理这些文件,则:

$ gnuplot plot-2d.plt$ gnuplot plot-2d-with-error-bars.plt$ gnuplot plot-3d.pt

会产生这些图像文件:
plot-2d.png
plot-2d-with-error-bars.png
plot-3d.png

——————————分割线 9.8, 2016————————-
上次只是从官网上看了下怎么在.cpp文件里写跟gnuplot相关的代码。这次实际演练了一下。用官方提供了示例文件。
ns-3-allinone/ns-3-dev/examples/tutorial/fifh.cc
这里写图片描述
我在命令行里的过程如下。
/home/cqq/repos/ns-3-allinone/ns-3-dev目录下运行:

$ ./waf --run fifth > cwnd.dat 2>&1

这样就将运行fifth.cc之后的结果重定向到cwnd.dat里面了,然后接下来,用gnuplot的交互式环境来生成.png图片文件。

gnuplot> set terminal png size 640,480 gnuplot> set output "condo.png"gnuplot> plot "cwnd.dat" using 1:2 title 'Congestion Window' with linespointsgnuplot> exit

然后就可以发现目录下已经有了一个cwnd.png图片文件了。
这里写图片描述
最后将mininet系统里的cwnd.png复制到宿主机OSX上查看图片。
这里写图片描述

0 0