Which command is used to label the x-axis and y-axis of the plot?
Which command is used to label the x-axis and y-axis of the plot?
Solution
In Matplotlib's pyplot module, plt.xlabel() sets the label of the x-axis and plt.ylabel() sets the label of the y-axis. Each takes the label text as a string, for example plt.xlabel("Year") and plt.ylabel("Sales").
Options 1, 3 and 4: pyplot has no functions named label_x(), label_y() or label() for axis labels. The names follow the pattern axis name first, then "label".
Use plt.title() for the plot title and plt.legend() to show the legend, which are often confused with the axis label functions.
Related questions:
2026: 29 May Shift 2
2025: 13 May Shift 2
2025: 20 May Shift 1
2025: 16 May Shift 1
2026: 26 May Shift 1
2026: 21 May Shift 1