-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdf_plot.py
More file actions
38 lines (31 loc) · 1.1 KB
/
cdf_plot.py
File metadata and controls
38 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Importing numpy, scipy, mpmath and pyplot
import numpy as np
import matplotlib.pyplot as plt
#if using termux
import subprocess
import shlex
#end if
x = np.linspace(-4,4,30)#points on the x axis
simlen = int(1e6) #number of samples
err = [] #declaring probability list
#randvar = np.random.normal(0,1,simlen)
randvar = np.loadtxt('uni.dat',dtype='double')
#randvar = np.loadtxt('gau.dat',dtype='double')
for i in range(0,30):
err_ind = np.nonzero(randvar < x[i]) #checking probability condition
err_n = np.size(err_ind) #computing the probability
err.append(err_n/simlen) #storing the probability values in a list
plt.plot(x.T,err)#plotting the CDF
plt.grid() #creating the grid
plt.xlabel('$x$')
plt.ylabel('$F_X(x)$')
#if using termux
#plt.savefig('../figs/uni_cdf.pdf')
#plt.savefig('../figs/uni_cdf.eps')
#subprocess.run(shlex.split("termux-open ../figs/uni_cdf.pdf"))
#if using termux
#plt.savefig('../figs/gauss_cdf.pdf')
#plt.savefig('../figs/gauss_cdf.eps')
#subprocess.run(shlex.split("termux-open ../figs/gauss_cdf.pdf"))
#else
plt.show() #opening the plot window