A. The transparent parameter should be a boolean, not a string
B. The filename must be .jpg for transparency
C. plt.plot() must be called after plt.savefig()
D. transparent parameter is not supported in plt.savefig()
Solution
Step 1: Check the type of transparent parameter
The transparent parameter expects a boolean value True or False, not a string like 'yes'.
Step 2: Understand correct usage of transparent
Passing a string will cause the parameter to be ignored or cause an error; it must be transparent=True for transparency.
Final Answer:
The transparent parameter should be a boolean, not a string -> Option A
Quick Check:
transparent=True is boolean, not string [OK]
Hint: Use True/False for transparent, not strings like 'yes' [OK]
Common Mistakes:
Passing 'yes' or 'no' as string instead of boolean
Using unsupported file formats for transparency
Calling plot after savefig
5. You want to save a matplotlib figure with a transparent background and ensure it blends well on any website background. Which file format and save command should you use?
hard
A. plt.savefig('figure.jpg', transparent=True) - JPEG supports transparency
B. plt.savefig('figure.bmp', transparent=True) - BMP supports transparency
C. plt.savefig('figure.svg', transparent=False) - SVG does not support transparency
D. plt.savefig('figure.png', transparent=True) - PNG supports transparency
Solution
Step 1: Identify file formats that support transparency
PNG and SVG support transparency; JPEG and BMP do not support transparent backgrounds properly.
Step 2: Choose correct save command for transparent background
Use transparent=True with a PNG file to save a transparent image that blends well on websites.
Final Answer:
plt.savefig('figure.png', transparent=True) - PNG supports transparency -> Option D
Quick Check:
PNG + transparent=True = best for transparent images [OK]
Hint: Use PNG format with transparent=True for best transparency [OK]
Common Mistakes:
Using JPEG or BMP which don't support transparency