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 ns.core
29
30# mu, var = 100, 225
31
32
33rng = ns.core.NormalRandomVariable()
34rng.SetAttribute("Mean", ns.core.DoubleValue(100.0))
35rng.SetAttribute("Variance", ns.core.DoubleValue(225.0))
36
37x = [rng.GetValue() for t in range(10000)]
38
39# the histogram of the data
40
41
42density = 1
43
44facecolor='g'
45
46alpha=0.75
47
48# We don't really need the plot results, we're just going to show it later.
49# n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
50plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
51
52plt.title('ns-3 histogram')
53plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
54plt.axis([40, 160, 0, 0.03])
55plt.grid(True)
56plt.show()