Resources

import warnings
warnings.filterwarnings("ignore")

### General Purpose
import numpy as np
from matplotlib import pyplot as plt
from scipy.integrate import odeint

### Jupyter Specifics
from IPython.display import HTML
from ipywidgets.widgets import interact, IntSlider, FloatSlider, Layout

%matplotlib inline

style = {'description_width': '150px'}
slider_layout = Layout(width='99%')

Calculation

def main(rabbits_birthrate, rabbits_deathrate, foxes_birthrate,
         foxes_deathrate, initial_rabbits, foxes_inicial, days):

    def function(s, t):
        x, y = s
        dydt = [
            rabbits_birthrate * x - rabbits_deathrate * x * y, # dx/dy -> Change in Rabbits
            foxes_birthrate * x * y - foxes_deathrate * y      # dy/dt -> Change in Foxes
        ]
        
        return dydt
    
    time = np.arange(0, days, 0.01)
    initial_conditions = [initial_rabbits, foxes_inicial]
    solution = odeint(function, initial_conditions, time)

    #Graphic details
    fig, axes = plt.subplots(1, 2, figsize=(15, 10))
    
    ax = axes[0]
    
    ax.plot(time, solution[:, 0], label='Rabbits(t)')
    ax.plot(time, solution[:, 1], label='Foxes(t)')
    
    if days <= 30:
        step = 1
        rotation = "horizontal"
    elif days <= 150:
        step = 5
        rotation = "vertical"
    else:
        step = 10
        rotation = "vertical"
    
    ax.set_xticklabels(np.arange(0, days + 1, step, dtype=int), rotation=rotation)
    ax.set_xticks(np.arange(0, days + 1, step))
        
    ax.set_xlim([0, days])
    ax.set_ylim([0, max(max(solution[:, 0]), max(solution[:, 1])) * 1.05])
    ax.set_xlabel('Time')
    ax.set_ylabel('Population')
    ax.legend(loc='best')
    ax.grid()
    
    
    ax = axes[1]
    
    ax.plot(solution[:, 0], solution[:, 1], label='Foxes vs Rabbits')

    ax.set_xlim([0, max(solution[:, 0]) * 1.05])
    ax.set_ylim([0, max(solution[:, 1]) * 1.05])
    ax.set_xlabel('Rabbits')
    ax.set_ylabel('Foxes')
    ax.legend(loc='best')
    ax.grid()
    
    plt.tight_layout()
    plt.show()

Evaluation

interact(main, 
        rabbits_birthrate=FloatSlider(min=1, max=25, step=1, value=1, 
               description='Birth Rate/Rabbits', style=style, layout=slider_layout),
        rabbits_deathrate=FloatSlider(min=1, max=25, step=1, value=1,
                description='Death Rate/Rabbits', style=style, layout=slider_layout),
        foxes_birthrate=FloatSlider(min=0, max=25, step=1, value=1,
                description='Birth Rate/Foxes', style=style, layout=slider_layout),
        foxes_deathrate=FloatSlider(min=0, max=25, step=1, value=1,
                description='Death Rate/Foxes', style=style, layout=slider_layout),
        initial_rabbits=FloatSlider(min=2 , max=100, step=1, value=2,
                description='Initial Rabbits', style=style, layout=slider_layout),
        foxes_inicial=FloatSlider(min=1 , max=100, step=1, value=1,
                description='Initial Foxes', style=style, layout=slider_layout),
        days=FloatSlider(min=15, max=365 , step=10, value=15,
                description='Number of Days', style=style, layout=slider_layout),
        );