CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Python for MATLAB Users

Afficher le cours

Instructions

  • Convert comments to Python syntax.
  • Replace MATLAB plotting functions with their corresponding pyplot functions.
  • Show your plot.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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)')

____.____()
Modifier et exécuter le code