Understand the idea
jointplot creates a central relationship plot with a distribution along each margin, all on its own Figure.
A small example
A central scatter pairs hours and score; the top margin describes hours and the side margin describes score.
Follow the code
Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.
import matplotlib.pyplot as plt
import seaborn as sns
g = sns.jointplot(data=df, x="hours", y="score", kind="scatter")
g.figure.tight_layout()
plt.show()What each part does
g = sns.jointplot(...)- create a relationship and its margins
kind="scatter"- central scatter plot
Your inputs
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
| student | club | hours | score | group |
|---|---|---|---|---|
| Ari | Art | 1 | 52 | A |
| Bo | Code | 3 | 71 | A |
| Cy | Art | 2 | 65 | B |
| Dee | Code | 4 | 82 | B |
| Eli | Art | 5 | 89 | A |
| Flo | Code | 3 | 76 | A |
| Gus | Art | 6 | 93 | B |
| Han | Code | 2 | 61 | B |
Your task · Follow
- Using df, call jointplot with x=hours, y=score, kind="scatter".
- This is a figure-level exception: do not create fig, ax first.
- Finish with g.figure.tight_layout() and plt.show().
Hint
jointplot owns a Figure with a central Axes and marginal Axes.
Reveal solution
One way to do it. Keep any supplied setup in the editor and use this in the Your work section.
import matplotlib.pyplot as plt
import seaborn as sns
g = sns.jointplot(data=df, x="hours", y="score", kind="scatter")
g.figure.tight_layout()
plt.show()