How to print the Y-axis label horizontally in a Matplotlib/Pylab chart?

MatplotlibServer Side ProgrammingProgramming

Just by using plt.ylabel(rotation='horizontal'), we can align a label according to our requirement.

Steps

  • Plot the lines using [0, 5] and [0, 5] lists.

  • Set the y-label for Y-axis, using ylabel method by passing rotation='horizontal'.

  • Set the x-label for X-axis, using xlabel method.

  • To show the plot, use plt.show() method.

Example

from matplotlib import pyplot as plt

plt.plot([0, 5], [0, 5])

plt.ylabel("Y-axis ", rotation='horizontal')
plt.xlabel("X-axis ")

plt.show()

Output

raja
Published on 17-Mar-2021 08:27:11
Advertisements