Consider the following command:
plt.hist(data, bins =10, color = 'red', edgecolor = 'blue')
What bins=10 specify?
Consider the following command:
plt.hist(data, bins =10, color = 'red', edgecolor = 'blue')
What bins=10 specify?
Solution
In plt.hist(), an integer value for bins sets the number of equal-width intervals. Matplotlib takes the range from the minimum to the maximum of the data and divides it into 10 equal-width bins. Each bar's height shows how many data points fall in that bin.
Option 1: bins does not filter or count data points. It only sets the number of intervals.
Option 2: Colour is set by color='red', which gives all bars one colour.
Option 4: Bar outlines are set by edgecolor='blue', which applies to every bar, not just the 10th.
Related questions:
2025: 30 May Shift 2
2026: 26 May Shift 1
2025: 27 May Shift 2
2026: 13 May Shift 2
2026: 24 May Shift 1