A Discrete-Event Network Simulator
API
sample-rng-plot.py
Go to the documentation of this file.
1# -*- Mode:Python; -*-
2# /*
3# * This program is free software; you can redistribute it and/or modify
4# * it under the terms of the GNU General Public License version 2 as
5# * published by the Free Software Foundation
6# *
7# * This program is distributed in the hope that it will be useful,
8# * but WITHOUT ANY WARRANTY; without even the implied warranty of
9# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# * GNU General Public License for more details.
11# *
12# * You should have received a copy of the GNU General Public License
13# * along with this program; if not, write to the Free Software
14# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15# */
16
17
24
25
26import numpy as np
27import matplotlib.pyplot as plt
28import sys
29import argparse
30from ns import ns
31
32
33def main():
34 parser = argparse.ArgumentParser("sample-rng-plot")
35 parser.add_argument("--not-blocking",
36 action="store_true",
37 default=False)
38 args = parser.parse_args(sys.argv[1:])
39
40 # mu, var = 100, 225
41
42
43 rng = ns.CreateObject("NormalRandomVariable")
44 rng.SetAttribute("Mean", ns.DoubleValue(100.0))
45 rng.SetAttribute("Variance", ns.DoubleValue(225.0))
46
47
48 x = [rng.GetValue() for t in range(10000)]
49
50 # the histogram of the data
51
52
53 density = 1
54
55 facecolor = 'g'
56
57 alpha = 0.75
58
59 # We don't really need the plot results, we're just going to show it later.
60 # n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
61 n, bins, patches = plt.hist(x, 50, density=True, facecolor='g', alpha=0.75)
62
63 plt.title('ns-3 histogram')
64 plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
65 plt.axis([40, 160, 0, 0.03])
66 plt.grid(True)
67 plt.show(block=not args.not_blocking)
68
69
70if __name__ == "__main__":
71 main()