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])
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
(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.
Related questions:
2025: 30 May Shift 2
2025: 3 June Shift 2
2025: 21 May Shift 1
2026: 19 May Shift 1