Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations · A little practice goes a long way.

← Visualise lessonsTINY TABLES · REAL PYTHON · YOUR PACE
Choose and build · V01 · 4 MIN

Meet Figure and Axes

Create the canvas and the plotting area.

Exercises within this concept

  1. FollowFollow the techniqueCurrent exercise

Understand the idea

A Figure is the whole canvas; an Axes is a plotting area inside it. Even one plotting area is called Axes.

Concept sketch: Figure contains the plotting AxesFigureAxesFigure contains the plotting Axes
Illustration · not the exercise output

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

  1. Create one empty Figure with one Axes at 6 by 4 inches.
  2. Give the chart title "Study club" and axis labels "hours" and "score".
  3. Finish with fig.tight_layout() and plt.show().
  4. 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()
Your task · Follow
  1. Create one empty Figure with one Axes at 6 by 4 inches.
  2. Give the chart title "Study club" and axis labels "hours" and "score".
  3. Finish with fig.tight_layout() and plt.show().
  4. Use: subplots().

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Display charts with plt.show().

Python starts when you open a lesson.

Output

Run your code to see what Python returns.