Arrange the following statements in proper order to plot bar chart.
(A) plt.savefig(stud.pdf')
(B) plt.show()
(C) import matplotlib.pyplot as plt
(D) plot.bar(['ram','sham','mohan','sohan'],[70,50,40,60])
Arrange the following statements in proper order to plot bar chart.
(A) plt.savefig(stud.pdf')
(B) plt.show()
(C) import matplotlib.pyplot as plt
(D) plot.bar(['ram','sham','mohan','sohan'],[70,50,40,60])
Solution
The order is (C), (D), (A), (B).
(C) comes first because the library must be imported before it can be used. (D) then draws the bar chart. (A) saves the figure to a file, and (B) comes last to display it.
Saving must come before plt.show(). After the plot window is shown and closed, the figure is cleared, so savefig() called afterwards would save a blank image.
Option 1: starts with saving, before any import or plot exists.
Option 2: calls plt.show() before the plot is drawn, so there would be nothing to display.
Option 3: starts with plt.show() and imports the library last, which gives an error.
Related questions:
2026: 26 May Shift 1
2025: 15 May Shift 2
2025: 14 May Shift 1
2026: 23 May Shift 1