Skip to main contentSkip to solution

Arrange the following statements to draw a Histogram. Assume 'pd' and 'plt' are alias names for pandas and matplotlib.pyplot respectively.

(A) plt.show()

(B) df=pd.read_csv('abc.csv')

(C) plt.legend()

(D) df.plot(kind='hist',label='RECORDS')

Solution

✅ Correct Option: 1

The data must be loaded first, then plotted, then the legend added, and finally the figure displayed.

(B) df=pd.read_csv('abc.csv') loads the data into a DataFrame.

(D) df.plot(kind='hist',label='RECORDS') draws the histogram and sets the label.

(C) plt.legend() shows the label set in the plot call, so it must come after (D).

(A) plt.show() renders the figure, so it comes last.


Option 3: plt.show() before the plot call would display nothing, and the legend would then have no plot to describe.

Option 4: the legend cannot be created before the data is loaded and plotted.

Keyboard Shortcuts

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