Set the axis labels in Matplotlib

Python

Matplotlib

Axes

Set labels

Luc B.

Python

Matplotlib

Axis labels are critical for making visualizations easy to understand. They clarify and provide context to the visualization.

Code Example

Use the plt.xlabel() and plt.ylabel() functions to set axis labels in Matplotlib.

import matplotlib.pyplot as plt

# Set the axis labels here
plt.xlabel("My 'X' Label")
plt.ylabel("My 'Y' Label")

plt.show()

png

More Examples

Object Oriented Interface

Matplotlib's object oriented interface implements the Axes.set_xlabel() and Axes.set_ylabel() functions to customize the axis labels.

ax = plt.axes()

# Set the axis labels here
ax.set_xlabel("My 'X' Label")
ax.set_ylabel("My 'Y' Label")

plt.show()

png