Complete the code to create a histogram of the data list using matplotlib.
import matplotlib.pyplot as plt data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] plt.[1](data) plt.show()
The hist function creates a histogram, which groups data into bins and shows frequency.
Complete the code to create a bar chart showing counts of categories using matplotlib.
import matplotlib.pyplot as plt categories = ['A', 'B', 'C'] counts = [5, 7, 3] plt.[1](categories, counts) plt.show()
The bar function creates a bar chart, which shows counts or values for categories.
Fix the error in the code to correctly plot a histogram of the data.
import matplotlib.pyplot as plt data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] plt.hist(data, bins=[1]) plt.show()
The bins parameter expects an integer number of bins, not a string or list.
Fill both blanks to create a dictionary comprehension that counts how many times each number appears in the list.
data = [1, 2, 2, 3, 3, 3] counts = {num: data.[1](num) for num in [2](data)}
len instead of count causes errors.list instead of set causes duplicate keys.The count method counts occurrences of each number, and set gets unique numbers.
Fill all three blanks to create a bar chart showing counts of unique items from data.
import matplotlib.pyplot as plt data = ['apple', 'banana', 'apple', 'orange', 'banana', 'banana'] counts = {item: data.count(item) for item in [1](data)} plt.bar(counts.[2](), counts.[3]()) plt.show()
list instead of set causes duplicate bars.keys() and values() causes wrong axes.set gets unique items, keys() gets the categories for x-axis, and values() gets counts for y-axis.