Skip to main contentSkip to solution

Arrange the following statements in proper order to plot the bar graph.

(A) plt.show()

(B) plt.savefig()

(C) import matplotlib.pyplot as plt

(D) plt.bar(['a','b','c','d'],[200,400,100,900])

Solution

✅ Correct Option: 4

(C) import matplotlib.pyplot as plt

The library must be imported before any plotting function can be used.

(D) plt.bar(['a','b','c','d'],[200,400,100,900])

This creates the bar graph with the given labels and heights.

(A) plt.show()

This displays the graph.

(B) plt.savefig()

This saves the figure to a file. It is listed last in the key's order.

In real code, plt.savefig() is usually called before plt.show(), because some backends clear the figure after it is shown. No option offers that order, so Option 4 is the best available.

Keyboard Shortcuts

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