Bird
0
0

You want to save a matplotlib plot as both PNG and PDF files with high resolution. Which code snippet correctly achieves this?

hard📝 Application Q8 of 15
Matplotlib - Export and Publication Quality
You want to save a matplotlib plot as both PNG and PDF files with high resolution. Which code snippet correctly achieves this?
Aplt.savefig('plot.png', resolution=300) plt.savefig('plot.pdf', resolution=300)
Bplt.savefig('plot.png') plt.savefig('plot.pdf')
Cplt.savefig('plot.png', dpi='high') plt.savefig('plot.pdf', dpi='high')
Dplt.savefig('plot.png', dpi=300) plt.savefig('plot.pdf', dpi=300)
Step-by-Step Solution
Solution:
  1. Step 1: Understand dpi parameter usage

    To save high resolution images, use dpi=300 (dots per inch) in savefig.
  2. Step 2: Check correct syntax for saving both formats

    plt.savefig('plot.png', dpi=300) plt.savefig('plot.pdf', dpi=300) correctly calls savefig twice with dpi=300 for PNG and PDF files.
  3. Final Answer:

    Use dpi=300 in savefig for both PNG and PDF -> Option D
  4. Quick Check:

    dpi=300 sets high resolution in savefig [OK]
Quick Trick: Use dpi=300 for high-res images in savefig [OK]
Common Mistakes:
  • Using invalid dpi values like 'high'
  • Using wrong parameter name 'resolution'
  • Not specifying dpi for high quality

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes