Bird
0
0

Identify the error in this code that tries to set font sizes for ticks:

medium📝 Debug Q14 of 15
Matplotlib - Export and Publication Quality
Identify the error in this code that tries to set font sizes for ticks:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.tick_params(axis='x', labelsize=14)
plt.yticks(fontsize='large')
plt.show()
Aplt.tick_params syntax is wrong
Bfontsize='large' is invalid for plt.yticks
Cplt.plot syntax is wrong
Dplt.show() is missing
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for tick font sizes

    Matplotlib expects labelsize=int in tick_params, not fontsize='large' in plt.yticks.
  2. Step 2: Identify which line has the error

    plt.yticks(fontsize='large') is invalid and will cause an error.
  3. Final Answer:

    fontsize='large' is invalid for plt.yticks -> Option B
  4. Quick Check:

    Use tick_params(labelsize=int) for ticks [OK]
Quick Trick: Use plt.tick_params(labelsize=number) for tick font sizes [OK]
Common Mistakes:
  • Using string values like 'large' for tick fontsize
  • Thinking plt.tick_params syntax is wrong
  • Ignoring error messages about parameter types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes