0
0
Data Analysis Pythondata~20 mins

Labels, titles, and legends in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Legend and Title Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the title of the plot?
Given the following Python code using matplotlib, what will be the title shown on the plot?
Data Analysis Python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.title('Sales Over Time')
plt.xlabel('Month')
plt.ylabel('Revenue')
plt.show()
ASales Over Time
BSales Data
CMonth
DRevenue
Attempts:
2 left
💡 Hint
Look for the plt.title() function argument.
data_output
intermediate
1:30remaining
How many legend entries will appear?
Consider this code snippet that plots two lines with labels for the legend. How many entries will the legend show?
Data Analysis Python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9], label='Squares')
plt.plot([1, 2, 3], [1, 8, 27], label='Cubes')
plt.legend()
plt.show()
A2
B3
C0
D1
Attempts:
2 left
💡 Hint
Count how many lines have a label argument.
🔧 Debug
advanced
2:00remaining
Why does the legend not show?
This code plots two lines with labels but the legend does not appear. What is the reason?
Data Analysis Python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [2, 4, 6], label='Double')
plt.plot([1, 2, 3], [3, 6, 9], label='Triple')
plt.show()
AThe plt.show() function must be called before plotting lines.
BThe labels are incorrect and cause an error preventing the legend.
CThe plt.legend() function is missing, so no legend is displayed.
DThe plot lines do not have colors, so the legend is hidden.
Attempts:
2 left
💡 Hint
Check if the legend function is called explicitly.
visualization
advanced
2:00remaining
Which option correctly adds a legend with a title?
You want to add a legend to your plot with the title 'Function Types'. Which code snippet does this correctly?
Data Analysis Python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9], label='Squares')
plt.plot([1, 2, 3], [1, 8, 27], label='Cubes')
# Add legend with title here
plt.show()
Aplt.legend(legend_title='Function Types')
Bplt.legend(label='Function Types')
Cplt.legend(title_label='Function Types')
Dplt.legend(title='Function Types')
Attempts:
2 left
💡 Hint
Check the official parameter name for legend title.
🧠 Conceptual
expert
2:00remaining
What happens if you call plt.title() multiple times?
If you call plt.title('First Title') and then plt.title('Second Title') before plt.show(), what will be the plot's title?
Data Analysis Python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [3, 2, 1])
plt.title('First Title')
plt.title('Second Title')
plt.show()
AThe plot will show both titles concatenated.
BThe plot will show 'Second Title' as the title.
CThe plot will show 'First Title' as the title.
DThe plot will have no title because of conflict.
Attempts:
2 left
💡 Hint
Think about how the title function updates the title property.