Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the figure size to 6 inches wide and 4 inches tall.
Matplotlib
import matplotlib.pyplot as plt plt.figure(figsize=([1], 4)) plt.plot([1, 2, 3], [4, 5, 6]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping width and height values.
Using pixels instead of inches.
✗ Incorrect
The figsize parameter takes a tuple (width, height) in inches. Here, width should be 6.
2fill in blank
mediumComplete the code to create a figure with width 8 inches and height 3 inches.
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=([1], 3)) ax.plot([0, 1], [0, 1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing width and height order.
Using integers as strings.
✗ Incorrect
The figsize tuple sets width first, so 8 is the correct width here.
3fill in blank
hardFix the error in the code to set the figure size to 5 inches wide and 2 inches tall.
Matplotlib
import matplotlib.pyplot as plt plt.figure(figsize=[1]) plt.plot([1, 2], [3, 4]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] instead of parentheses.
Passing two separate numbers without tuple.
✗ Incorrect
The figsize parameter requires a tuple, so (5, 2) is correct.
4fill in blank
hardFill both blanks to create a figure with width 7 inches and height 5 inches, then plot a line.
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=([1], [2])) ax.plot([0, 1, 2], [2, 3, 4]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping width and height values.
Using incorrect numbers.
✗ Incorrect
The figsize tuple is (width, height), so 7 and 5 are correct.
5fill in blank
hardFill all three blanks to create a figure with width 4 inches, height 3 inches, and plot a red dashed line.
Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=([1], [2])) ax.plot([1, 2, 3], [3, 2, 1], linestyle=[3], color='red') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong order for width and height.
Using wrong linestyle string.
✗ Incorrect
Width is 4, height is 3, and linestyle '--' creates a dashed line.