Bird
Raised Fist0
Data Analysis Pythondata~5 mins

Figure and axes creation in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is a figure in data visualization?
A figure is the entire window or page that holds one or more plots or charts. Think of it as a blank canvas where you draw your graphs.
Click to reveal answer
beginner
What is an axes in a figure?
Axes are the parts of the figure where the actual data is plotted. It includes the x-axis, y-axis, and the area where the graph appears.
Click to reveal answer
beginner
How do you create a figure and axes using Matplotlib in Python?
Use the command fig, ax = plt.subplots(). This creates a figure and a single axes inside it, ready for plotting.
Click to reveal answer
intermediate
Why might you want to create multiple axes in one figure?
To show multiple plots side by side or in a grid, making it easier to compare data visually in one window.
Click to reveal answer
beginner
What does the figsize parameter control when creating a figure?
It sets the size of the figure in inches, controlling how big or small the whole plot area will be.
Click to reveal answer
Which command creates a figure and axes in Matplotlib?
Afig, ax = plt.subplots()
Bplt.create_figure()
Caxes = plt.figure()
Dplot.figure()
What does an axes object represent?
AThe entire plotting window
BThe area where data is plotted including axes lines
COnly the x-axis line
DThe title of the plot
How can you create multiple plots in one figure?
ABy calling plt.plot() multiple times
BBy using plt.figure() multiple times
CBy creating multiple axes using plt.subplots() with rows and columns
DBy changing the figure size
What does the figsize parameter control?
AThe size of the figure in inches
BThe number of axes
CThe font size of labels
DThe color of the plot
If you want a single plot, which is the simplest way to create figure and axes?
Aplt.axes() only
Bplt.figure() only
Cplt.plot() only
Dfig, ax = plt.subplots()
Explain the difference between a figure and axes in data visualization.
Think of a figure as a page and axes as the drawing area on that page.
You got /3 concepts.
    Describe how to create multiple plots in one figure using Python's Matplotlib.
    Consider how you might arrange photos in a photo album.
    You got /3 concepts.

      Practice

      (1/5)
      1. What does the plt.subplots() function return in matplotlib?
      easy
      A. A figure and one or more axes objects
      B. Only a figure object
      C. Only an axes object
      D. A list of data points

      Solution

      1. Step 1: Understand plt.subplots() purpose

        The function is designed to create a figure and axes together for plotting.
      2. Step 2: Check the return values

        It returns a tuple: the first is the figure, the second is the axes (single or array).
      3. Final Answer:

        A figure and one or more axes objects -> Option A
      4. Quick Check:

        plt.subplots() = (figure, axes) [OK]
      Hint: Remember plt.subplots() returns figure and axes together [OK]
      Common Mistakes:
      • Thinking it returns only figure or only axes
      • Confusing axes with data points
      • Assuming it returns a plot directly
      2. Which of the following is the correct syntax to create a figure with 2 rows and 3 columns of axes using matplotlib?
      easy
      A. fig, axes = plt.subplots(rows=3, cols=2)
      B. fig, axes = plt.subplots(2, 3)
      C. fig, axes = plt.subplots(3, 2)
      D. fig, axes = plt.subplots(2*3)

      Solution

      1. Step 1: Recall plt.subplots() parameters

        The first argument is number of rows, the second is number of columns.
      2. Step 2: Match the correct order

        To create 2 rows and 3 columns, use plt.subplots(2, 3).
      3. Final Answer:

        fig, axes = plt.subplots(2, 3) -> Option B
      4. Quick Check:

        Rows first, columns second in plt.subplots() [OK]
      Hint: Remember rows first, columns second in plt.subplots() [OK]
      Common Mistakes:
      • Swapping rows and columns order
      • Using keyword arguments incorrectly
      • Passing a single number instead of two
      3. What will be the shape of axes when running fig, axes = plt.subplots(2, 2)?
      medium
      A. A 2x2 numpy array of AxesSubplot objects
      B. A list of 4 AxesSubplot objects
      C. A single AxesSubplot object
      D. A dictionary of axes objects

      Solution

      1. Step 1: Understand axes structure for multiple subplots

        When more than one subplot is created, axes is a 2D array matching the grid shape.
      2. Step 2: Check the shape for 2 rows and 2 columns

        Axes will be a 2x2 numpy array of AxesSubplot objects.
      3. Final Answer:

        A 2x2 numpy array of AxesSubplot objects -> Option A
      4. Quick Check:

        Multiple subplots = axes array matching grid [OK]
      Hint: Multiple subplots return axes array matching rows and columns [OK]
      Common Mistakes:
      • Expecting a flat list instead of 2D array
      • Thinking axes is a single object always
      • Confusing axes with figure
      4. Identify the error in this code snippet:
      fig, ax = plt.subplots(2, 2)
      ax.plot([1, 2, 3], [4, 5, 6])
      medium
      A. fig and ax are swapped in assignment
      B. plt.subplots() cannot create 2x2 axes
      C. ax is an array, so ax.plot() causes an error
      D. The plot data lists have different lengths

      Solution

      1. Step 1: Check the shape of ax from plt.subplots(2, 2)

        ax is a 2x2 array of axes, not a single axes object.
      2. Step 2: Understand why ax.plot() fails

        Calling plot() on an array causes an AttributeError because arrays don't have plot method.
      3. Final Answer:

        ax is an array, so ax.plot() causes an error -> Option C
      4. Quick Check:

        Array of axes needs indexing before plot() [OK]
      Hint: Index axes array before plotting when multiple subplots exist [OK]
      Common Mistakes:
      • Trying to plot on axes array directly
      • Assuming plt.subplots(2,2) returns single axes
      • Ignoring need to index axes for plotting
      5. You want to create a figure with 3 subplots stacked vertically and set the figure size to 8 inches wide and 12 inches tall. Which code correctly does this?
      hard
      A. fig, axes = plt.subplots(1, 3, figsize=(12, 8))
      B. fig, axes = plt.subplots(3, figsize=(8, 12))
      C. fig, axes = plt.subplots(3, 1, size=(8, 12))
      D. fig, axes = plt.subplots(3, 1, figsize=(8, 12))

      Solution

      1. Step 1: Determine subplot layout for vertical stacking

        3 subplots stacked vertically means 3 rows and 1 column.
      2. Step 2: Set figure size correctly

        Use figsize=(width, height) with width=8 and height=12 inches.
      3. Final Answer:

        fig, axes = plt.subplots(3, 1, figsize=(8, 12)) -> Option D
      4. Quick Check:

        Rows=3, cols=1, figsize=(8,12) [OK]
      Hint: Use figsize=(width, height) and rows, columns order [OK]
      Common Mistakes:
      • Swapping rows and columns
      • Using wrong keyword 'size' instead of 'figsize'
      • Confusing width and height order
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard