Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to save the plot with a transparent background.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.savefig('plot.png', transparent=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a boolean for the transparent parameter.
Forgetting to set transparent=True and getting a white background.
✗ Incorrect
Setting transparent=True saves the plot with a transparent background.
2fill in blank
mediumComplete the code to create a figure with a transparent background.
Matplotlib
import matplotlib.pyplot as plt fig = plt.figure(facecolor=[1]) plt.plot([1, 2, 3], [3, 2, 1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'transparent' which is not a valid color name.
Using 'white' which makes the background white, not transparent.
✗ Incorrect
Setting facecolor='none' makes the figure background transparent.
3fill in blank
hardFix the error in the code to save the plot with a transparent background.
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1]) plt.savefig('plot.png', transparent=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'True' as a string instead of True as a boolean.
Using 1 which may work but is not the recommended boolean.
✗ Incorrect
The transparent parameter must be a boolean True, not a string.
4fill in blank
hardFill both blanks to create and save a plot with a transparent figure and save background.
Matplotlib
import matplotlib.pyplot as plt fig = plt.figure(facecolor=[1]) plt.plot([1, 2, 3], [1, 4, 9]) plt.savefig('plot.png', transparent=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'white' for facecolor which is not transparent.
Setting transparent=False which disables transparency on save.
✗ Incorrect
Use facecolor='none' for transparent figure background and transparent=True to save with transparent background.
5fill in blank
hardFill all three blanks to create a transparent figure, plot data, and save with transparent background.
Matplotlib
import matplotlib.pyplot as plt fig = plt.figure(facecolor=[1]) plt.plot([[2]], [[3]]) plt.savefig('plot.png', transparent=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'white' for facecolor which is not transparent.
Swapping x and y data lists causing confusing plots.
✗ Incorrect
facecolor='none' makes figure background transparent; plotting x=[1,2,3] and y=[3,2,1] shows data; saving with transparent=True keeps background transparent.