Skip to main contentSkip to solution

Which of the following histogram functions are correct?

import matplotlib.pyplot as plt

(A). plt.bar( )

(B). plt.hist( )

(C). plt.plot(kind= 'hist')

(D). plt.plot(kind = 'histogram')

Solution

✅ Correct Option: 3

plt.hist() is matplotlib's dedicated histogram function. The plot type given as kind='hist' is also treated as a histogram, so (B) and (C) are the correct pair.


(A): plt.bar() draws a bar chart, where each bar is a category with a given height. A histogram instead bins continuous data into intervals.

(D): 'histogram' is not a valid plot kind. The accepted string is 'hist'.

Remember that bar charts have gaps between bars and histograms do not.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question