In [1]:
%matplotlib inline
import os
from rfsim.librfsim import librfsim
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
In [2]:
landscape = librfsim.CLandscape()
landscape.setup(10, 10, 10)
landscape.iterate(1)
rabbits_start = landscape.get_rabbits()
foxes_start = landscape.get_foxes()
In [3]:
sns.heatmap(rabbits_start)
plt.show()

Now create an animation of number of rabbits over time

In [4]:
rabbits_list = []
foxes_list = []
for i in range(100):
    landscape.iterate(10)
    rabbits_list.append(landscape.get_rabbits().copy())
    foxes_list.append(landscape.get_foxes().copy())
In [5]:
def initial_plot_rabbits():
    data = np.zeros(shape=(100, 100))
    return sns.heatmap(data, square=True, vmin=0, vmax=100)

def initial_plot_foxes():
    data = np.zeros(shape=(100, 100))
    return sns.heatmap(data, square=True, vmin=0, vmax=10)
In [6]:
def animate_plot_rabbits(i):
    plt.clf()
    data = rabbits_list[i]
    return sns.heatmap(data, square=True, vmin=0, vmax=1000)

def animate_plot_foxes(i):
    plt.clf()
    data = foxes_list[i]
    return sns.heatmap(data, square=True, vmin=0, vmax=10)
In [7]:
%matplotlib notebook
%matplotlib notebook
fig = plt.figure()
anim = FuncAnimation(fig, animate_plot_rabbits, frames=100, 
                     init_func=initial_plot_rabbits, repeat = False)
plt.show()
In [8]:
%matplotlib notebook
%matplotlib notebook
fig = plt.figure()
anim = FuncAnimation(fig, animate_plot_foxes, frames=100, init_func=initial_plot_foxes, repeat = False)
plt.show()