Complete the code to create a vertical bar chart using plt.bar.
import matplotlib.pyplot as plt categories = ['A', 'B', 'C'] values = [5, 7, 3] plt.[1](categories, values) plt.show()
The plt.bar function creates a vertical bar chart using the categories and their values.
Complete the code to add labels to the x-axis of the bar chart.
import matplotlib.pyplot as plt categories = ['X', 'Y', 'Z'] values = [4, 6, 8] plt.bar(categories, values) plt.[1]('Categories') plt.show()
The plt.xlabel function sets the label for the x-axis, which in this case are the categories.
Fix the error in the code to correctly display the bar chart with custom colors.
import matplotlib.pyplot as plt categories = ['P', 'Q', 'R'] values = [10, 15, 7] colors = ['red', 'green', 'blue'] plt.bar(categories, values, [1]=colors) plt.show()
The correct parameter name to set bar colors in plt.bar is color.
Fill both blanks to create a bar chart with a title and y-axis label.
import matplotlib.pyplot as plt categories = ['Jan', 'Feb', 'Mar'] values = [20, 25, 30] plt.bar(categories, values) plt.[1]('Monthly Sales') plt.[2]('Sales') plt.show()
plt.title adds a title to the chart, and plt.ylabel labels the y-axis.
Fill all three blanks to create a bar chart with custom colors, x-axis label, and title.
import matplotlib.pyplot as plt categories = ['Red', 'Green', 'Blue'] values = [7, 3, 5] colors = ['#FF0000', '#00FF00', '#0000FF'] plt.bar(categories, values, [1]=colors) plt.[2]('Colors') plt.[3]('Color Counts') plt.show()
Use color to set bar colors, xlabel to label the x-axis, and title to add a chart title.