ns3--Making Plots using the Gnuplot Class

原文链接:
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 linespoints
gnuplot> exit

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值