Complete the code to import the library needed to create bar charts.
import [1] as plt
We use matplotlib.pyplot to create bar charts in Python.
Complete the code to create a simple bar chart from the data.
plt.bar([1], [5, 7, 3]) plt.show()
The x-axis labels should be categorical names like ["A", "B", "C"] to match the bar heights.
Fix the error in the code to correctly label the bars.
labels = ["Red", "Blue", "Green"] values = [10, 15, 7] plt.bar(range(len(values)), values) plt.xticks([1], labels) plt.show()
The plt.xticks() function needs the positions of the bars, which is range(len(values)).
Fill both blanks to create a bar chart with custom colors and title.
colors = [[1]] plt.bar(["A", "B", "C"], [3, 6, 9], color=[2]) plt.title("[3]") plt.show()
We use a list of color names for the color argument and add a title string.
Fill all three blanks to create a horizontal bar chart with labels and values.
labels = ["Apple", "Banana", "Cherry"] values = [10, 5, 8] plt.barh([1], [2], color="orange") plt.xlabel("[3]") plt.show()
For horizontal bars, labels go on the y-axis and values on the x-axis. The xlabel describes the values.
