我在Pycharm 2017.3.3 Community Edition中遇到了一个奇怪的问题。我正在编写一个循环,每次迭代都应该显示不同的图形。当我运行代码时,只有第一张图显示出来,程序就会卡住。如果我在没有断点的情况下以调试模式运行代码,情况也是一样的。然而,如果我设置一个断点,并在达到断点时继续执行程序,所有的图形都会显示出来,程序可以成功执行。还想澄清一下,我之前用过这段代码,只有少量图形时运行良好。
以下是代码:
以下是代码:
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()