Matplotlib is a very powerful plotting library useful for those working with Python and NumPy. And for making statistical interference, it becomes very necessary to visualize our data and Matplotlib is the tool that can be very helpful for this purpose.
matplotlib.pyplot.ylabel()
This function sets the label for the y-axis of the plot.
Syntax: matplotlib.pyplot.ylabel(ylabel, fontdict=None, labelpad=None)
Parameters:
ylabel: The name of the label
fontdict: Adds the font styles to the label
labelpad: This helps us to set the spacing between label and the axis
Example #1:
import matplotlib.pyplot as plt # setting x values x = [ 'Geeks' , 'for' , 'Lazyroar' , 'tutorials' ] # Setting y values y = [ 1 , 2 , 3 , 4 ] # Adding label on the y-axis plt.ylabel( 'Numbers label' ) # plotting the graph plt.plot(x, y) |
Output:
Example #2:
import matplotlib.pyplot as plt x = [ 'Geeks' , 'for' , 'Lazyroar' , 'tutorials' ] y = [ 1 , 2 , 3 , 4 ] # Adding space between label and # axis by setting labelpad plt.ylabel( 'Numbers label' , labelpad = 50 ) plt.plot(x, y) |
Output:
Example #3:
import matplotlib.pyplot as plt x = [ 'Geeks' , 'for' , 'Lazyroar' , 'tutorials' ] y = [ 1 , 2 , 3 , 4 ] # Setting font dictionary font = { 'family' : 'Verdana' , 'color' : 'green' , 'size' : 20 , } # Adding the font styles to the label plt.ylabel( 'Numbers label' , fontdict = font) plt.plot(x, y) |
Output:
<!–
–>
Please Login to comment…