Which function is used to create a histogram in Matplotlib?
Analysis & Theory
`plt.hist()` is the function used to create histograms in Matplotlib.
What does a histogram represent?
A
Frequency of each unique value
B
Relationship between two variables
C
Distribution of data over continuous intervals
D
Comparison of categorical data
Analysis & Theory
A histogram shows the frequency distribution of continuous numeric data.
Which parameter controls the number of bins in a histogram?
Analysis & Theory
`bins` determines how many intervals or bars the data will be divided into.
What does `plt.hist(data, bins=5)` do?
A
Splits the data into 5 pieces
C
Divides the data into 5 intervals
Analysis & Theory
This divides the full data range into 5 bins or intervals and plots the frequency in each.
What is the default orientation of a histogram in Matplotlib?
Analysis & Theory
Histograms are vertical by default unless `orientation='horizontal'` is set.
How can you normalize the histogram so total area equals 1?
Analysis & Theory
Setting `density=True` makes the area under the histogram sum to 1.
Which parameter changes the color of the bars in a histogram?
Analysis & Theory
Use `color='blue'` (or any color name) to change the fill color of the histogram bars.
What does the `histtype='step'` parameter do?
B
Draws an outline around each bar
C
Creates a step outline histogram
D
Draws vertical lines only
Analysis & Theory
`histtype='step'` draws only the outlines of the histogram bins, like steps.
How can you add a grid to the histogram plot?
Analysis & Theory
`plt.grid(True)` adds a grid to any Matplotlib plot, including histograms.
How do you display multiple histograms on the same plot?
A
Use a loop over `plt.hist()` calls with same axes
B
Only one histogram is allowed per figure
C
Call `plt.multi_hist()`
D
Use `plt.hist(data, multiple=True)`
Analysis & Theory
Calling `plt.hist()` multiple times before `plt.show()` will overlay multiple histograms on the same plot.