0
0
Matplotlibdata~10 mins

Figure creation with plt.figure in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new figure using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.[1]()
Drag options to blanks, or click blank then click option'
Ashow
Bplot
Cfigure
Dsubplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot() instead of plt.figure()
Using plt.show() to create a figure
Using plt.subplot() which creates subplots, not a figure
2fill in blank
medium

Complete the code to create a figure with a specific size of 8 by 6 inches.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=[1])
Drag options to blanks, or click blank then click option'
A(8, 6)
B[8, 6]
C(6, 8)
D[6, 8]
Attempts:
3 left
💡 Hint
Common Mistakes
Using list instead of tuple for figsize
Swapping width and height values
Using single values instead of a tuple
3fill in blank
hard

Fix the error in the code to create a figure with a title 'My Plot'.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
fig.[1]('My Plot')
Drag options to blanks, or click blank then click option'
Atitle
Bsuptitle
Cset_label
Dset_title
Attempts:
3 left
💡 Hint
Common Mistakes
Using fig.title() which does not exist
Using set_title() which is for axes, not figure
Using set_label() which is unrelated
4fill in blank
hard

Fill both blanks to create a figure with a size of 10 by 4 inches and a blue background color.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=[1], facecolor=[2])
Drag options to blanks, or click blank then click option'
A(10, 4)
B(4, 10)
C'blue'
D'red'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping width and height in figsize
Using color names without quotes
Using list instead of tuple for figsize
5fill in blank
hard

Fill all three blanks to create a figure with a size of 12 by 5 inches, a green background, and a tight layout.

Matplotlib
import matplotlib.pyplot as plt
fig = plt.figure(figsize=[1], facecolor=[2])
fig.[3]()
Drag options to blanks, or click blank then click option'
A(12, 5)
B'green'
Ctight_layout
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping width and height in figsize
Using wrong method name for layout adjustment
Forgetting parentheses after method call