plt.show is a function and needs parentheses to execute.
Step 2: Verify style name and plot arguments
'dark_background' is a valid style, and plot arguments are correctly ordered.
Final Answer:
Missing parentheses in plt.show call -> Option C
Quick Check:
plt.show() needs parentheses to display plot [OK]
Hint: Always call plt.show() with parentheses [OK]
Common Mistakes:
Forgetting parentheses on plt.show
Assuming style name is invalid without checking
Thinking plot arguments order causes error
5. You want to create a bar chart with a style that uses a dark background and grid lines. Which code snippet correctly applies the style and plots the data?
import matplotlib.pyplot as plt
data = [5, 7, 3]
labels = ['A', 'B', 'C']
# Choose the correct code to apply style and plot
hard
A. plt.bar(labels, data)
plt.style.use('dark_background')
plt.show()
B. plt.style.use('dark_background')
plt.bar(labels, data)
plt.show()
C. plt.style.use('ggplot')
plt.bar(labels, data)
plt.show()
D. plt.style('dark_background')
plt.bar(labels, data)
plt.show()
Solution
Step 1: Apply style before plotting
Style must be set before plotting to affect the chart appearance.
Step 2: Check style name and plotting method
'dark_background' is the correct style for dark theme with grid lines; plt.bar plots bar chart correctly.
Step 3: Verify plt.show() usage
plt.show() is called with parentheses to display the plot.
Final Answer:
plt.style.use('dark_background')
plt.bar(labels, data)
plt.show() -> Option B
Quick Check:
Set style before plot, use plt.show() [OK]
Hint: Set style before plotting, call plt.show() with () [OK]
Common Mistakes:
Setting style after plotting
Using plt.style instead of plt.style.use
Forgetting parentheses on plt.show
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.