Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the library needed to create bar charts.
Data Analysis Python
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing pandas or numpy instead of matplotlib.pyplot.
Using seaborn without importing matplotlib.pyplot.
✗ Incorrect
We use matplotlib.pyplot to create bar charts in Python.
2fill in blank
mediumComplete the code to create a simple bar chart from the data.
Data Analysis Python
plt.bar([1], [5, 7, 3]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers as x-axis labels without meaning.
Using a list of values that does not match the bar heights.
✗ Incorrect
The x-axis labels should be categorical names like ["A", "B", "C"] to match the bar heights.
3fill in blank
hardFix the error in the code to correctly label the bars.
Data Analysis Python
labels = ["Red", "Blue", "Green"] values = [10, 15, 7] plt.bar(range(len(values)), values) plt.xticks([1], labels) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing labels instead of positions to plt.xticks.
Passing values instead of positions to plt.xticks.
✗ Incorrect
The plt.xticks() function needs the positions of the bars, which is range(len(values)).
4fill in blank
hardFill both blanks to create a bar chart with custom colors and title.
Data Analysis Python
colors = [[1]] plt.bar(["A", "B", "C"], [3, 6, 9], color=[2]) plt.title("[3]") plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers instead of color names for colors.
Not adding a title or using a wrong type for title.
✗ Incorrect
We use a list of color names for the color argument and add a title string.
5fill in blank
hardFill all three blanks to create a horizontal bar chart with labels and values.
Data Analysis Python
labels = ["Apple", "Banana", "Cherry"] values = [10, 5, 8] plt.barh([1], [2], color="orange") plt.xlabel("[3]") plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping labels and values in the barh function.
Not labeling the x-axis properly.
✗ Incorrect
For horizontal bars, labels go on the y-axis and values on the x-axis. The xlabel describes the values.