A. A scatter plot with labels 'Low', 'Medium', 'High'
B. A line plot with default numeric x-axis labels 0, 1, 2
C. An error because plt.xticks() is used incorrectly
D. A line plot with x-axis labels 'Low', 'Medium', 'High' at positions 0, 1, 2
Solution
Step 1: Understand the plot and xticks usage
The plot shows points at y-values 10, 20, 30 with default x positions 0, 1, 2.
Step 2: Analyze plt.xticks() effect
plt.xticks([0, 1, 2], ['Low', 'Medium', 'High']) replaces x-axis tick labels at positions 0,1,2 with the given strings.
Final Answer:
A line plot with x-axis labels 'Low', 'Medium', 'High' at positions 0, 1, 2 -> Option D
Quick Check:
xticks sets custom labels at given positions [OK]
Hint: xticks changes labels, not plot type [OK]
Common Mistakes:
Thinking xticks changes plot type
Expecting numeric labels after setting strings
Confusing positions and labels order
4. Identify the error in this code that tries to rotate x-axis tick labels:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.xticks(rotation=45)
plt.show()
medium
A. No error; code runs correctly
B. plt.xticks() needs positions and labels to rotate
C. plt.xticks() must be called before plt.plot()
D. rotation argument is not valid in plt.xticks()
Solution
Step 1: Check plt.xticks() usage with rotation
plt.xticks() can be called with rotation parameter alone to rotate existing tick labels.
Step 2: Confirm code correctness
The code plots points and rotates x-axis labels by 45 degrees without needing to specify positions or labels.
Final Answer:
No error; code runs correctly -> Option A
Quick Check:
Rotation works with plt.xticks(rotation=angle) [OK]
Hint: Rotation works without specifying labels [OK]
Common Mistakes:
Thinking positions are required to rotate labels
Believing rotation is invalid argument
Assuming plot order affects xticks rotation
5. You have a bar chart with 5 bars. You want to set custom labels ['A', 'B', 'C', 'D', 'E'] on the x-axis and rotate them 60 degrees for better readability. Which code snippet correctly does this?
hard
A. plt.xticks(range(5), ['A', 'B', 'C', 'D', 'E'], rotation=60)
B. plt.xticks(['A', 'B', 'C', 'D', 'E'], range(5), rotation=60)
C. plt.xticks(rotation=60)
plt.xticks(range(5), ['A', 'B', 'C', 'D', 'E'])
D. plt.xticks(range(5), ['A', 'B', 'C', 'D', 'E'])
plt.xticks(rotation=60)
Solution
Step 1: Understand plt.xticks() parameters
plt.xticks() takes positions as first argument, labels as second, and rotation as a keyword argument.
Step 2: Check which option sets labels and rotation together
plt.xticks(range(5), ['A', 'B', 'C', 'D', 'E'], rotation=60) correctly passes positions, labels, and rotation in one call.
Step 3: Analyze other options
plt.xticks(['A', 'B', 'C', 'D', 'E'], range(5), rotation=60) swaps positions and labels incorrectly; A and C call plt.xticks() twice, which may override settings.
Final Answer:
plt.xticks(range(5), ['A', 'B', 'C', 'D', 'E'], rotation=60) -> Option A
Quick Check:
Set labels and rotation in one plt.xticks() call [OK]
Hint: Use plt.xticks(positions, labels, rotation=angle) [OK]
Common Mistakes:
Swapping positions and labels arguments
Calling plt.xticks() twice causing override
Forgetting to pass rotation argument
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.