Matplotlib – Set Y Label for Plot

To set Y-Label for plot in matplotlib, call ylabel()function on matplotlib.pyplot object and pass the required label value as string.

The following code snippet shows how to set the Y label for plot with the string “Sample Y-Label”.

import matplotlib.pyplot as plt

plt.ylabel('Sample Y-Label')

Example

In this example, we will draw a plot, and set its y-label to “Sample Y-Label”.

example.py

import matplotlib.pyplot as plt

# x axis and y axis data
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
y = [5, 7, 8, 1, 4, 9, 6, 3, 5, 2, 1, 8]

plt.plot(x, y)

#set y-label for plot axes
plt.ylabel('Sample Y-Label')

plt.show()

Output

Matplotlib - Set Y Label for Plot
Set Y label to “Sample Y-Label” for Plot

Conclusion

Concluding this Matplotlib Tutorial, we learned how to set Y-Label for plot in matplotlib.