Bird
0
0

How do you correctly save a matplotlib plot with a transparent background using plt.savefig()?

easy📝 Syntax Q3 of 15
Matplotlib - Export and Publication Quality
How do you correctly save a matplotlib plot with a transparent background using plt.savefig()?
A<code>plt.savefig('plot.png', alpha=0.5)</code>
B<code>plt.savefig('plot.png', transparent=True)</code>
C<code>plt.savefig('plot.png', bg='transparent')</code>
D<code>plt.savefig('plot.png', transparent='yes')</code>
Step-by-Step Solution
Solution:
  1. Step 1: Use plt.savefig()

    This function saves the current figure to a file.
  2. Step 2: Set transparent=True

    Passing transparent=True makes the figure background transparent when saving.
  3. Final Answer:

    plt.savefig('plot.png', transparent=True) -> Option B
  4. Quick Check:

    Check the parameter name and value type. [OK]
Quick Trick: Use transparent=True in plt.savefig() for transparent background [OK]
Common Mistakes:
  • Using 'transparent' with string values instead of boolean
  • Using 'alpha' parameter which controls plot transparency, not background
  • Using incorrect parameter names like 'bg' or 'background'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes