Bird
0
0

What will be the file format of the saved plot after running this code?

medium📝 Predict Output Q4 of 15
Matplotlib - Export and Publication Quality
What will be the file format of the saved plot after running this code?
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.savefig('myplot.pdf')
APNG image
BPDF document
CSVG vector image
DJPEG image
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the filename extension in savefig

    The filename is 'myplot.pdf', so matplotlib will save the plot as a PDF document.
  2. Step 2: Confirm file format matches extension

    Since the extension is '.pdf', the output file is a PDF document.
  3. Final Answer:

    The saved file is a PDF document -> Option B
  4. Quick Check:

    File extension '.pdf' = PDF document [OK]
Quick Trick: File extension in savefig determines output format [OK]
Common Mistakes:
  • Assuming default PNG format
  • Confusing PDF with SVG
  • Ignoring file extension

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes