Bird
0
0

Which code snippet correctly sets the figure size and saves the plot?

hard📝 Application Q15 of 15
Matplotlib - Export and Publication Quality
You want to create a publication-ready plot with a width of 7 inches and height of 5 inches. You also want to save it as a PNG file with 300 dpi resolution. Which code snippet correctly sets the figure size and saves the plot?
Aplt.figure(figsize=(7, 5)) plt.plot(data) plt.savefig('plot.png', dpi=300)
Bplt.figure(size=(7, 5)) plt.plot(data) plt.savefig('plot.png', dpi=300)
Cplt.figure(figsize=[7, 5]) plt.plot(data) plt.savefig('plot.png')
Dplt.figure(figsize=(7, 5)) plt.plot(data) plt.save('plot.png', dpi=300)
Step-by-Step Solution
Solution:
  1. Step 1: Set figure size correctly

    Use figsize=(7, 5) tuple in plt.figure() to set width and height in inches.
  2. Step 2: Save figure with correct dpi and function

    Use plt.savefig('plot.png', dpi=300) to save with 300 dpi resolution. plt.figure(size=(7, 5)) plt.plot(data) plt.savefig('plot.png', dpi=300) uses wrong parameter size. plt.figure(figsize=[7, 5]) plt.plot(data) plt.savefig('plot.png') misses dpi. plt.figure(figsize=(7, 5)) plt.plot(data) plt.save('plot.png', dpi=300) uses wrong function plt.save.
  3. Final Answer:

    plt.figure(figsize=(7, 5)) plt.plot(data) plt.savefig('plot.png', dpi=300) -> Option A
  4. Quick Check:

    figsize tuple + savefig with dpi=300 [OK]
Quick Trick: Use figsize tuple and savefig with dpi for publication [OK]
Common Mistakes:
  • Using 'size' instead of 'figsize'
  • Forgetting dpi in savefig for quality
  • Using plt.save instead of plt.savefig

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes