Plotting maps in loops

I created random arrays to simplify everything. Here it is:

import numpy as np

import matplotlib.pyplot as plt

population=np.random.rand(30,30) Attractivity_max=np.random.rand(30,30) Available_max=np.random.rand(30,30) allocated=np.random.rand(30,30) new_population_map=np.zeros(np.shape(population)) new_pop=population.sum() dt=1 r=0.05 for i in range(0,20,dt): year=2011+i while year <= 2030: new_pop = new_pop(1+rdt) dt=dt+1 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) if new_pop==0: break if new_pop>Available_max[max_index_att]: new_pop=new_pop-Available_max[max_index_att] allocated[max_index_att] = Available_max[max_index_att] elif new_pop<Available_max[max_index_att]: new_pop=Available_max[max_index_att]-new_pop allocated[max_index_att] = new_pop new_population_map[max_index_att]=allocated[max_index_att]+population[max_index_att] Available_max[max_index_att]=0 Attractivity_max[max_index_att]=0 break plt.figure() plt.imshow(new_population_map) plt.colorbar() plt.title('New population map')
print('done')

Thank you so much, really

/r/learnpython Thread Parent