-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathplot.py
85 lines (66 loc) · 2.25 KB
/
plot.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import numpy as np
import matplotlib.pyplot as plt
labelTextSize = 14
def plotBER(BERSets, xval, xlabel, title=None, legend=None, semilog=True, show=True, savePath=None):
plt.figure(figsize=(16,9))
for BER in BERSets:
if semilog:
BER = np.array(BER)
BER[BER<1e-3] = -1
plt.semilogy(xval, BER, '-o', nonposy='mask')
else:
plt.plot(xval, BER, '-o')
plt.tick_params(labelsize=labelTextSize)
plt.xlabel(xlabel, fontsize=labelTextSize)
plt.ylabel('BER', fontsize=labelTextSize)
plt.ylim([0,1.0])
plt.grid()
if title is not None:
plt.title(title, fontsize=labelTextSize)
else:
plt.title("Bit Error Rates", fontsize=labelTextSize)
if legend is not None:
plt.legend(legend, fontsize=labelTextSize)
if savePath is not None:
plt.savefig(savePath, dpi=300)
if show:
plt.show()
else:
plt.close()
def plotCCDF(paprDbSet, steps=0.1, title=None, legend=None, show=True, savePath=None):
if not isinstance(paprDbSet, list):
paprDbList = [paprDbSet]
else:
paprDbList = paprDbSet
plt.figure(figsize=(16, 9))
# plotting for all sets of paprDb vals provided
for paprDb in paprDbList:
valRange = np.arange(np.min(paprDb), np.max(paprDb), steps)
y = np.zeros(valRange.shape)
for vdx, val in enumerate(valRange):
# calculating probability of papr > val
y[vdx] = (len(paprDb[paprDb > val]) / (1.0 * len(paprDb)))
# adding to plot
plt.plot(valRange, y, '-o')
plt.tick_params(labelsize=labelTextSize)
plt.xlabel('Z (dB)', fontsize=labelTextSize)
plt.ylabel('Prob (PAPR > Z)', fontsize=labelTextSize)
plt.grid()
if title is not None:
plt.title(title, fontsize=labelTextSize)
else:
plt.title("CCDF for PAPR", fontsize=labelTextSize)
if legend is not None:
plt.legend(legend, fontsize=labelTextSize)
if savePath is not None:
plt.savefig(savePath, dpi=300)
if show:
plt.show()
else:
plt.close()
def plotImages(imgs):
plt.figure(figsize=(16,9))
for i in range(len(imgs)):
plt.subplot(len(imgs),1,i+1)
plt.imshow(imgs[i])
plt.show()