%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
landscape = librfsim.CLandscape()
landscape.setup(10, 10, 10)
landscape.iterate(1)
rabbits_start = landscape.get_rabbits()
foxes_start = landscape.get_foxes()
sns.heatmap(rabbits_start)
plt.show()
Now create an animation of number of rabbits over time
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())
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)
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)
%matplotlib notebook
%matplotlib notebook
fig = plt.figure()
anim = FuncAnimation(fig, animate_plot_rabbits, frames=100,
init_func=initial_plot_rabbits, repeat = False)
plt.show()
%matplotlib notebook
%matplotlib notebook
fig = plt.figure()
anim = FuncAnimation(fig, animate_plot_foxes, frames=100, init_func=initial_plot_foxes, repeat = False)
plt.show()