Plotting multiple plots in one diagram with ns3

676 views
Skip to first unread message

stefanhe...@googlemail.com

unread,
Apr 3, 2013, 2:31:36 AM4/3/13
to ns-3-...@googlegroups.com
Hey everybody!

I just found the option to use gnuplot with ns3. Only problem I got is that I can not figure it out to plot multiple plots in one diagram, which I can do with gnuplot itself. The code I use is similar to this simple example:

//datasets
Gnuplot2dDataset data1;
Gnuplot2dDataset data2;

//random data
data1.Add(Simulator::Now ().GetSeconds (), value11);
data1.Add(Simulator::Now ().GetSeconds (), value12);
data2.Add(Simulator::Now ().GetSeconds (), value21);
data2.Add(Simulator::Now ().GetSeconds (), value22);

//Gnuplot
Gnuplot plot (diagram + ".png");
plot.SetTerminal ("png");
plot.SetLegend ("Time s" , "Number of Packets");

data1.SetTitle("one");
data2.SetTitle("two");

data1.SetStyle(Gnuplot2dDataset::LINES_POINTS);
data2.SetStyle(Gnuplot2dDataset::LINES_POINTS);

plot.AddDataset(data1);
plot.AddDataset(data2);

// Open the plot file.
std::ofstream plotFile ((diagram + ".plt").c_str());

// Write the plot file.
plot.GenerateOutput (plotFile);

// Close the plot file.
plotFile.close ();

There is no diagram generated at all and when I try to gnuplot the .plt file I get the following error:

plot '-'  title 'sent' with linespoints, '-'  title 'failed' with linespoints
                            ^
"Diagramm.plt", line 6: warning: Skipping data file with no valid points

The related .plt looks like this:

set terminal png
set output 'Diagramm.png'
set xlabel 'Time s'
set ylabel 'Number of Packets'
plot '-'  title 'sent' with linespoints, '-'  title 'failed' with linespoints
e
1.089 1
1.276 2
1.383 3
1.7 4
1.755 5
2.232 6
2.458 7
2.59 8
3 9
3.922 10
e

When using just one plot thus calling the AddDataset() just once everything works fine and I can even use the .plt file to generate the same diagram as the script does with gnuplot.

I appreciate every help and greets!

Mitch Watrous

unread,
Apr 3, 2013, 3:08:10 PM4/3/13
to ns-3-...@googlegroups.com
It looks like the second data set is empty in the .plt file and that doesn't match your code snippet.

Make sure that data2 is not empty, i.e. has values added to it.

Mitch
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages