Python 循环绘制地图

Python 循环绘制地图,python,dictionary,matplotlib,plot,Python,Dictionary,Matplotlib,Plot,我已经创建了一个代码,在20年的时间里逐步填充数组的不同单元格。 我希望每年在地图中绘制阵列的结果,因此我最终会绘制20个图。 然而,无论我如何缩进绘图代码,我要么以无数显示进化的绘图结束,但它一直在无休止地绘图,要么以20个不显示进化的绘图结束 感谢您的帮助 dt=1 r=0.05 #Loop for every year and calculate allocated spaces for i in range(0,20,dt): year=2011+i while y

我已经创建了一个代码,在20年的时间里逐步填充数组的不同单元格。 我希望每年在地图中绘制阵列的结果,因此我最终会绘制20个图。 然而,无论我如何缩进绘图代码,我要么以无数显示进化的绘图结束,但它一直在无休止地绘图,要么以20个不显示进化的绘图结束

感谢您的帮助

dt=1
r=0.05
#Loop for every year and calculate allocated spaces  
for i in range(0,20,dt):
    year=2011+i 
    while year <= 2030:
        new_pop = new_pop*(1+r*dt)
        #print(new_pop)
        #Loop through attractivity map and for every max value find available space and fill it 
        for i in range(Attractivity_max.shape[0]):
            for j in range(Attractivity_max.shape[1]):
                max_index_att = np.unravel_index(np.argmax(Attractivity_max, axis=None), Attractivity_max.shape) #find indices of max attractivity value
                #print(max_index_att)
                #print(available_space[max_index_att])
                #print(new_pop)
                if new_pop==0:
                    break
                if new_pop>Available_max[max_index_att]:
                    new_pop=new_pop-Available_max[max_index_att] #assign people to available spaces in pixel with max attractiveness 
                    #print(new_pop)
                    allocated[max_index_att] = Available_max[max_index_att] #available space has been allocated 
                elif new_pop<Available_max[max_index_att]:
                    new_pop=Available_max[max_index_att]-new_pop #assign people to available spaces in pixel with max attractiveness 
                    #print(new_pop)
                    allocated[max_index_att] = new_pop #available space has been allocated 
                    Available_max[max_index_att]=0 #available space taken up --> now 0 
                    Attractivity_max[max_index_att]=0 #old max becomes 0 in order to find new max 
                    
        plt.figure()
        plt.imshow(allocated)
        plt.colorbar(label='allocated space')
        plt.title('Allocated population map')
        
        break
    #print(year)
print('done')
dt=1
r=0.05
#每年循环并计算分配的空间
对于范围(0,20,dt)内的i:
年份=2011+i
可用年份\u max[最大索引\u att]:
new_pop=new_pop-Available_max[max_index_att]#将人员分配到具有最大吸引力的像素中的可用空间
#打印(新流行音乐)
已分配的[max_index_att]=可用的[max_index_att]#已分配可用空间
elif new_pop now 0
吸引力_max[max_index_att]=0#旧的max变为0以找到新的max
plt.图()
plt.imshow(已分配)
plt.colorbar(label='allocated space')
plt.title(‘分配人口图’)
打破
#印刷品(年)
打印(‘完成’)