Advertisement
paulnakroshis

Set up forest

Oct 26th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. """
  4. Percolation.py
  5.  
  6. Created by Paul Nakroshis on 2011-10-26.
  7. This code by Paul Andrew Nakroshis is licensed under
  8. a Creative Commons Attribution-NonCommercial-ShareAlike
  9. 3.0 Unported License.
  10.  
  11. """
  12. import matplotlib.pylab as plt
  13. import matplotlib as mlab
  14. import numpy as np
  15. forestColors = mlab.colors.ListedColormap(('white','green','red','black'))
  16. N=100
  17. probOfTree=0.1
  18. forest = np.zeros((N,N))
  19. for i in range(N):
  20.     for j in range(N):
  21.         p = np.random.rand()
  22.         if p <= probOfTree:   # site has tree if p < probOfTree
  23.             forest[i,j]=0.30  # color of grid site set to green
  24.         else:
  25.             forest[i,j]=0.0   # unoccupied sites are white
  26.  
  27. plt.pcolor(forest,cmap=forestColors,vmin=0.0,vmax=1.0)
  28. plt.colorbar()
  29. plt.show()
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement