I am having a weird problem in Pycharm 2017.3.3 Community Edition. I am making a cycle that is supposed to show different figures in each iteration. When I run the code, only the first figure shows and the program gets stuck. The same happens if I run the code in debug mode with no breakpoints. However, if I set a breakpoint, and keep resuming the program when it reaches the breakpoint, all the figures are shown and the program finishes the execution successfully. Also wanted to clarify that I have used the code before with less figures and it had worked out fine.
Here is the code:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from sklearn.externals import joblib
feat_file = 'C:\\Users\\DianaCarolina\\Google Drive\\Maestría\\datos\\indices_Diana\\all_type.xlsx'
sites = {"Bosque":['5256', '5260'], "Rastrojo": ['5253', '5255'], "Pastizal": ['5257', '7125']}
model=joblib.load("C:\\Users\\DianaCarolina\\Google Drive\\Maestría\\datos\\indices_Diana\\ecotyhmm13_3.pkl")
nclasses = 13
for comp in range(nclasses):
histData = []
types = []
col = []
for type in sites:
df = pd.read_excel(feat_file, sheet_name=type, index_col=0)
mdata=df.loc[df.iloc[:, 20] == comp, "Mes"]
types.append(type)
histData.append(mdata)
if len(col) < 3:
if type == "Bosque" and "green" not in col:
col.append("green")
elif type == "Rastrojo" and "orange" not in col:
col.append("orange")
elif type == "Pastizal" and "yellow" not in col:
col.append("yellow")
mclass = np.sum(np.array([model.gmms_[comp].weights_]).T * model.gmms_[comp].means_, 0)
plt.figure()
if not histData[0].empty or not histData[1].empty or not histData[2].empty:
plt.subplot(2, 1, 1)
n, bins, patches = plt.hist(histData, np.arange(0.5,13, 1), stacked=True, label= types, color = col, rwidth=0.8)
plt.legend()
plt.xticks(range(1,13), ("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", \
"Septiembre", "Octubre", "Noviembre", "Diciembre"))
plt.title("Clase "+str(comp+1)+" de "+str(nclasses))
plt.subplot(2, 1, 2)
plt.stem(mclass)
plt.xticks(range(14), list(df.loc[:, "M":"Salida2_4"]))
plt.title("Medias de características para la clase")
plt.show()