Python videos

# Plotting: Exercises and Solutions

## Plotting heart-rate distributions in subplots

### Exercise

Use this dataset from Moore, McCabe, & Craig to create a two-by-two plot, and in each subplot show the distribution of heart rate for one combination of gender and group of participants (Men Runners, Men Control, Female Runners, Female Control).

### Solution

``````from matplotlib import pyplot as plt
import seaborn as sns
from datamatrix import io, operations as ops

plt.subplot(2, 2, 1)
plt.title('Female Runners')
dm_female_runner = (dm.Gender == 'Female') & (dm.Group == 'Runners')
sns.distplot(dm_female_runner['Heart Rate'])
plt.subplot(2, 2, 2)
plt.title('Female Control')
dm_female_control = (dm.Gender == 'Female') & (dm.Group == 'Control')
sns.distplot(dm_female_control['Heart Rate'])
plt.subplot(2, 2, 3)
plt.title('Male Runners')
dm_male_runner = (dm.Gender == 'Male') & (dm.Group == 'Runners')
sns.distplot(dm_male_runner['Heart Rate'])
plt.subplot(2, 2, 4)
plt.title('Male Control')
dm_male_control = (dm.Gender == 'Male') & (dm.Group == 'Control')
sns.distplot(dm_male_control['Heart Rate'])
plt.show()
``````

Output:

``````<string>:13: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

similar flexibility) or `histplot` (an axes-level function for histograms).

For a guide to updating your code to use the new functions, please see

[32mâ ¹[0m Generating...<string>:17: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

similar flexibility) or `histplot` (an axes-level function for histograms).

For a guide to updating your code to use the new functions, please see

[32mâ ¸[0m Generating...<string>:21: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

similar flexibility) or `histplot` (an axes-level function for histograms).

For a guide to updating your code to use the new functions, please see

[32mâ ¼[0m Generating...<string>:25: UserWarning:

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.