I need help in debugging. I just can't figure out why it's not working as expected.
The Code below should read data files (names are stored in all_files
) in chunks of 6, arrange them in subplots (i,j indices 0,0 top left, 1,2 bottom right), show plot.
It works for the first six file names and the plot is being showed. When I close the window of the plot, the code continues and ends without showing the next plot... is plt.show()
at a wrong place?
fig, axes = plt.subplots(nrows=cond_row, ncols=cond_col)k=0 # step
i=0 # indice
j=0 # indicefor z in range(0, len(all_files), 6):for fe in all_files[z:z+6]:get_name_tag = re.findall(".A(\d{7}).", all_files[k])[0]for label, values in data_1_band.items():if label == str(get_name_tag):axes[i, j].set_title("Band " + str(Band_names[specific_band]) +" - "+ "file: "+ str(label))axes[i, j].set_ylabel("Along-Track Scans")axes[i, j].set_xlabel("Along-Scan Scans")im1 = axes[i, j].imshow(values, interpolation="none")cb = fig.colorbar(im1, ax=axes[i, j], label='W $\mathrm{m^{-2}}$ $\mathrm{\mu m^{-1}}$ $\mathrm{ster^{-1}}$')# Taking mean from data and finds location on colorbarmean_loc = (L_B_1_mean[label] - cb.vmin) / (cb.vmax - cb.vmin)# add a horizontal line to the colorbar axiscb.ax.hlines(mean_loc, 0, 1, label="Mean")#Columns conditionj=j+1k=k+1if j==3:print "entered if condition: new line"i=i+1j=0if i==2: # Plot is full, resetting for next plotj=0i=0# deleting axes in case there are no 6 files leftif len(all_files) < 4:fig.delaxes(axes[1][0])fig.delaxes(axes[1][1])fig.delaxes(axes[1][2])if len(all_files) < 5:fig.delaxes(axes[1][1])fig.delaxes(axes[1][2])if len(all_files) < 6:fig.delaxes(axes[1][2]) plt.show()
Files:
all_files
looks like this:
MYD021KM.A2009049.0930.006.2012060021525.hdf
MYD021KM.A2010305.0900.006.2012070143225.hdf
MYD021KM.A2010321.0900.006.2012071073516.hdf
MYD021KM.A2010337.0900.006.2012071175047.hdf
MYD021KM.A2010353.0900.006.2012072063847.hdf
MYD021KM.A2010001.0900.006.2012065165320.hdf
.....
data_1_band
: (How can I upload a file, so you could run the code?)
2009161 [[ 3.58403872 3.57167339 3.60095971 ..., 7.01769751 6.809439216.88883769][ 3.40962239 3.51960881 3.54954594 ..., 6.97864908 6.894044147.03657092][ 3.26384158 3.51244993 3.63089684 ..., 6.89729818 6.994919267.11922343]..., [ 8.26724734 8.05183015 7.79801534 ..., 8.21583357 8.243167478.24772312][ 8.17288029 8.11691087 7.66655229 ..., 8.21648437 8.202817428.09998989][ 8.26659653 7.93012921 7.49929484 ..., 8.19305531 8.188499668.10845038]]
2009065 [[ 6.12674245 6.25950712 6.74045364 ..., 7.12377909 7.110762947.0977468 ][ 6.08509079 6.22761757 6.86215459 ..., 7.13093796 7.122477477.11336617][ 6.07728111 6.19702963 6.61745108 ..., 7.13939846 7.125731517.11727101]...,