Understand the idea
A Figure is the whole canvas; an Axes is a plotting area inside it. Even one plotting area is called Axes.
A small example
fig, ax = plt.subplots(figsize=(6, 4)) creates a canvas 6 inches wide and 4 inches high with one plotting area.
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
fig, ax = plt.subplots(figsize=(6, 4))
ax.set(title="Study club", xlabel="hours", ylabel="score")
fig.tight_layout()
plt.show()What each part does
import matplotlib.pyplot as plt- load plotting tools
fig, ax =- unpack two returned objects
plt.subplots(figsize=(6, 4))- canvas width and height in inches
plt.show()- display the figure
Your task · Follow
- Create one empty Figure with one Axes at 6 by 4 inches.
- Give the chart title "Study club" and axis labels "hours" and "score".
- Finish with fig.tight_layout() and plt.show().
- Use: subplots().
Hint
subplots returns the whole Figure and its Axes; unpack both names.
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
fig, ax = plt.subplots(figsize=(6, 4))
ax.set(title="Study club", xlabel="hours", ylabel="score")
fig.tight_layout()
plt.show()