import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
import pickle


with open('../A1_DICT', 'rb') as fp:
  vdict = pickle.load(fp)

print(vdict.keys())
print(len(vdict[0]))
with open('../A2_DICT', 'rb') as fp:
  vdict2 = pickle.load(fp)

with open('../A3_DICT', 'rb') as fp:
  vdict3 = pickle.load(fp)

with open('../A4_DICT', 'rb') as fp:
  vdict4 = pickle.load(fp)


#print(sorted(vdict.keys()))
#print(sorted(vdict2.keys()))





fig, axes = plt.subplots(nrows=4, ncols=4)


a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict[x][0])
    except:
        a.append(vdict[x][len(vdict[x])-1])

axes[0][0].imshow(a, vmin=0,vmax=1, alpha=0.9,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict[x][25])
    except:
        a.append(vdict[x][len(vdict[x])-1])


#[m,n] = np.shape(a)
axes[0][1].imshow(a, vmin=0,vmax=1, alpha=0.9,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict[x][40])
    except:
        a.append(vdict[x][len(vdict[x])-1])


#[m,n] = np.shape(a)
axes[0][2].imshow(a, vmin=0,vmax=1, alpha=0.9,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
  a.append(vdict[x][len(vdict[x])-1])

#[m,n] = np.shape(a)
#print(len(vdict[1]))

im = axes[0][3].imshow(a, vmin=0,vmax=1, alpha=0.9,  cmap='copper', interpolation='antialiased')






a = []
for x in sorted(vdict.keys()):
  try:
    a.append(vdict2[x][0])
  except:
    a.append(vdict2[x][len(vdict2[x])-1])

#[m,n] = np.shape(a)
axes[1][0].imshow(a, vmin=0,vmax=1, alpha=0.99,  cmap='copper', interpolation='antialiased')


a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict2[x][25])
    except:
        a.append(vdict2[x][len(vdict2[x])-1])


#[m,n] = np.shape(a)
axes[1][1].imshow(a, vmin=0,vmax=1, alpha=0.99,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict2[x][40])
    except:
        a.append(vdict2[x][len(vdict2[x])-1])


#[m,n] = np.shape(a)
axes[1][2].imshow(a, vmin=0,vmax=1, alpha=0.99,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
  #print(x, vdict2[x][len(vdict2[x])-1])
  a.append(vdict2[x][len(vdict2[x])-1])

#[m,n] = np.shape(a)
im = axes[1][3].imshow(a, vmin=0,vmax=1, alpha=0.9,  cmap=cm.copper, interpolation='antialiased')





##############################

a = []
for x in sorted(vdict.keys()):
  try:
      a.append(vdict3[x][0])
  except:
      a.append(vdict3[x][len(vdict3[x])-1])

#[m,n] = np.shape(a)
axes[2][0].imshow(a, vmin=0,vmax=1, alpha=0.99,  cmap='copper', interpolation='antialiased')


a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict3[x][25])
    except:
        a.append(vdict3[x][len(vdict3[x])-1])


#[m,n] = np.shape(a)
axes[2][1].imshow(a, vmin=0,vmax=1, alpha=0.99,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict3[x][40])
    except:
        a.append(vdict3[x][len(vdict3[x])-1])


#[m,n] = np.shape(a)
axes[2][2].imshow(a, vmin=0,vmax=1, alpha=0.99,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
  #print(x, np.sum(vdict3[x][len(vdict3[x])-1]))
  a.append(vdict3[x][len(vdict3[x])-1])

#[m,n] = np.shape(a)
im = axes[2][3].imshow(a, vmin=0,vmax=1, alpha=0.9,  cmap=cm.copper, interpolation='antialiased')


#################################


a = []
for x in sorted(vdict.keys()):
  a.append(vdict4[x][0])

#print(a)
#exit()
#[m,n] = np.shape(a)
axes[3][0].imshow(a, vmin=0,vmax=1, alpha=0.99,  cmap='copper', interpolation='antialiased')


a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict4[x][25])
    except:
        a.append(vdict4[x][len(vdict4[x])-1])


#[m,n] = np.shape(a)
axes[3][1].imshow(a, vmin=0,vmax=1,  alpha=0.99,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
    try:
        a.append(vdict4[x][40])
    except:
        a.append(vdict4[x][len(vdict4[x])-1])


#[m,n] = np.shape(a)
axes[3][2].imshow(a, vmin=0,vmax=1,  alpha=0.99,  cmap='copper', interpolation='antialiased')



a = []
for x in sorted(vdict.keys()):
 # print(len(vdict4[x]))
 # print(x, vdict4[x][len(vdict4[x])-1])
  a.append(vdict4[x][len(vdict4[x])-1])

#[m,n] = np.shape(a)
im = axes[3][3].imshow(a, vmin=0,vmax=1, alpha=0.9,  cmap=cm.copper, interpolation='antialiased')

















cbar_ax = fig.add_axes([0.85, 0.15, 0.01, 0.7])

fig.subplots_adjust(right=0.8)
fig.colorbar(im, cax=cbar_ax)
#fig.colorbar(im, ax=axes.ravel().tolist())


plt.show()


