What predicts animal longevity?
Let's pull this all together & port some MATLAB code over to Python.
A colleague sent you their MATLAB analysis of data from "AnAge: The Animal Ageing and Longevity Database." This database contains longevity data for over 4000 vertebrate animals, along with other data related to longevity.
You've loaded up the data in Python, and now you want to understand the relationship between the maximum longevity (stored in the numpy array max_longevity
) of animals and the number of litters they produce each year (in litters_per_year
). You've already imported pyplot and assigned it to the variable plt
.
You have their MATLAB code plotting this relationship, but you need to port it over to Python.
This exercise is part of the course
Python for MATLAB Users
Exercise instructions
- Convert comments to Python syntax.
- Replace MATLAB plotting functions with their corresponding
pyplot
functions. - Show your plot.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
% Initialize the figure
figure
% Make the scatter plot
scatter(litters_per_year, max_longevity)
% Add axis labels
xlabel('Litters/Clutches per year')
ylabel('Maximum longevity (yrs)')
____.____()