-
Notifications
You must be signed in to change notification settings - Fork 0
/
plots.py
120 lines (89 loc) · 4.48 KB
/
plots.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.patches as patches
from matplotlib.ticker import MaxNLocator
import matplotlib
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
textsize = 10
fig_width = 6
fig_height = 2
def plot_causal_factorization(SLS_data, F, Dec, Enc):
# plot sparsity of causal factorization
epsilon = 1e-10 # threshold to plot sparsity using pyploy.spy
#F = F[0:-2, 0:-2]
#Dec = Dec[0:-2, :]
#Enc = Enc[:, 0:-2]
(n_rows, n_cols) = np.shape(F)
band = np.shape(Enc)[0]
gs2 = gridspec.GridSpec(1, 3, width_ratios = [n_cols, band, n_cols])
fig = plt.figure()
axs20 = plt.subplot(gs2[0,0])
axs21 = plt.subplot(gs2[0,1])
axs22 = plt.subplot(gs2[0,2])
axs20.spy(F, epsilon, markersize=0.8, color='r', label='$\mathbf{K}$')
axs21.spy(Dec, epsilon, markersize=0.8, color='r', label='$\mathbf{D}$')
axs22.spy(Enc, epsilon, markersize=0.8, color='r', label='$\mathbf{E}$')
axs20.yaxis.set_major_locator(MaxNLocator(integer=True)) # integer ticks on axis
axs20.xaxis.set_major_locator(MaxNLocator(integer=True))
axs21.yaxis.set_major_locator(MaxNLocator(integer=True))
axs21.xaxis.set_major_locator(MaxNLocator(integer=True))
axs22.yaxis.set_major_locator(MaxNLocator(integer=True))
axs22.xaxis.set_major_locator(MaxNLocator(integer=True))
step_ticks = 10
axs20.set_xticks(np.arange(step_ticks-1,SLS_data.T*SLS_data.ny,step_ticks), np.arange(step_ticks,SLS_data.T*SLS_data.ny+1, step_ticks))
axs20.set_yticks(np.arange(step_ticks-1,SLS_data.T*SLS_data.nu,step_ticks), np.arange(step_ticks,SLS_data.T*SLS_data.nu+1, step_ticks))
axs20.tick_params(axis='both', labelsize=textsize+3)
axs21.set_xticks(np.arange(step_ticks-1,Dec.shape[1],step_ticks), np.arange(step_ticks,Dec.shape[1]+1, step_ticks))
axs21.set_yticks(np.arange(step_ticks-1,SLS_data.T*SLS_data.nu,step_ticks), np.arange(step_ticks,SLS_data.T*SLS_data.nu+1, step_ticks))
axs21.tick_params(axis='both', labelsize=textsize+3)
axs22.set_yticks(np.arange(step_ticks-1,Enc.shape[0],step_ticks), np.arange(step_ticks,Enc.shape[0]+1, step_ticks))
axs22.set_xticks(np.arange(step_ticks-1,SLS_data.T*SLS_data.ny,step_ticks), np.arange(step_ticks,SLS_data.T*SLS_data.ny+1, step_ticks))
axs22.tick_params(axis='both', labelsize=textsize+3)
axs20.grid(); axs21.grid(); axs22.grid()
axs20.legend(markerscale=0, handlelength=-0.8); axs21.legend(markerscale=0, handlelength=-0.8); axs22.legend(markerscale=0, handlelength=-0.8)
fig.set_size_inches(fig_width+2, fig_height+3)
axs20.set_aspect(1.3); axs21.set_aspect(1.3); axs22.set_aspect(1.3)
fig.tight_layout()
return fig
def plot_transmission_times(fig, transmission_times, T, **kwargs):
plt.step( [0]+transmission_times+[T], [0]+list(range(1,len(transmission_times)+1))+[len(transmission_times)], where='post', **kwargs)
ax=fig.gca()
ax.set_xlabel("Time step")
ax.set_ylabel("Nbr. of transmissions")
ax.yaxis.set_major_locator(MaxNLocator(integer=True)) # integer ticks on axis
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
ax.legend()
ax.grid()
#fig.tight_layout()
plt.rc('xtick', labelsize=textsize)
plt.rc('ytick', labelsize=textsize)
plt.rcParams.update({'font.size': textsize})
fig.set_size_inches(fig_width, fig_height)
def plot_transmissions_vs_tol(list_truncation_tol, list_n_transmission, **kwargs):
fig = plt.figure()
plt.plot(list_truncation_tol, list_n_transmission, **kwargs)
plt.xscale("log")
ax=fig.gca()
ax.set_xlabel('$\epsilon$')
ax.set_ylabel('Nbr. of transmissions')
ax.grid()
ax.yaxis.set_major_locator(MaxNLocator(integer=True)) # integer ticks on axis
plt.rc('xtick', labelsize=textsize)
plt.rc('ytick', labelsize=textsize)
plt.rcParams.update({'font.size': textsize})
fig.set_size_inches(fig_width, fig_height)
return fig
def plot_transmissions_vs_gamma(fig, list_gamma, list_n_transmission_gamma, **kwargs):
plt.plot(list_gamma, list_n_transmission_gamma, **kwargs)
ax=fig.gca()
ax.set_xlabel('$\gamma$')
ax.set_ylabel('Nbr. of transmissions')
ax.yaxis.set_major_locator(MaxNLocator(integer=True)) # integer ticks on axis
ax.legend()
plt.rc('xtick', labelsize=textsize)
plt.rc('ytick', labelsize=textsize)
plt.rcParams.update({'font.size': textsize})
fig.set_size_inches(fig_width, fig_height)
ax.grid(linestyle='-')