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 plt.hist() function creates a histogram, which shows the distribution of data.
Complete the code to set the number of bins to 4 in the histogram.
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 controls how many bars the histogram has. Here, 4 bins split the data into 4 groups.
Fix the error in the code to correctly display the histogram with labels.
import matplotlib.pyplot as plt data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] plt.hist(data) plt.xlabel([1]) plt.ylabel('Frequency') plt.show()
The label text must be a string, so it needs quotes like 'Value'.
Fill both blanks to create a histogram with 5 bins and a title.
import matplotlib.pyplot as plt data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] plt.hist(data, bins=[1]) plt.title([2]) plt.show()
Set bins=5 to split data into 5 groups and use a string with quotes for the title.
Fill all three blanks to create a histogram with 6 bins, x-label, and y-label.
import matplotlib.pyplot as plt data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] plt.hist(data, bins=[1]) plt.xlabel([2]) plt.ylabel([3]) plt.show()
Use bins=6 for six groups, and label axes with strings in quotes.