Skip to main contentSkip to solution

Which command is used to label the x-axis and y-axis of the plot?

Solution

✅ Correct Option: 2

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.

Keyboard Shortcuts

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