Which of the following function will be used to label the x axis of a plot?
Which of the following function will be used to label the x axis of a plot?
Solution
✅ Correct Option: 2
In Matplotlib, plt.xlabel("text") sets the label of the x-axis of the current plot. For example, plt.xlabel("Time") writes "Time" below the x-axis.
plt.ylabel() does the same for the y-axis.
Option 1: xaxis is an attribute of an Axes object (as in ax.xaxis), not a pyplot function that sets a label.
Options 3 and 4: plt.setx() and plt.axislabel() do not exist in pyplot.
Related questions:
2025: 27 May Shift 2
2026: 23 May Shift 1
2026: 23 May Shift 2