Python | Pyplot Labelling

Python | Pyplot Labelling: In this article, we are going to learn types of labels in a Pyplot API with the examples.
Submitted by Anuj Singh, on July 15, 2020

There are the following types of labels,

1) X-axis labelling

plt.xlabel('Number Line')
# Default labelling
Python | Pyplot Labelling (1)

plt.xlabel('Number Line', color='green')
#Font colour Changed
Python | Pyplot Labelling (2)

plt.xlabel('Number Line', color='Green', fontsize=15)
#Font size Change
Python | Pyplot Labelling (3)

plt.xlabel('Number Line', color='Green', fontsize=15, bbox=dict(facecolor='yellow', alpha=0.5))
#Background Box Addition with opaque ratio
Python | Pyplot Labelling (4)

2) Y-axis labelling

plt.ylabel('Function')
#Default Labelling
Python | Pyplot Labelling (5)

plt.xlabel('Function', color='green')
#Colour Change
Python | Pyplot Labelling (6)

plt.xlabel('Function', color='Green', fontsize=15)
#Font Size Modification
Python | Pyplot Labelling (7)

plt.xlabel('Function', color='Green', fontsize=15, bbox=dict(facecolor='yellow', alpha=0.5))
#Background Box Addition with opaque ratio
Python | Pyplot Labelling (8)

Pythion code to demonstrate example of pyplot labelling

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(500)
y1 = np.arange(500)
for i in range(500):
    y1[i] = 2*x[i] + np.random.randint(0,56)

#x-axis labelling
#default 
plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line')

#Colour
plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line', color='green')

#size 
plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line', color='Green', fontsize=15)

#Background Box
plt.figure()
plt.plot(x,y1)
plt.xlabel('Number Line', color='Green', fontsize=15, bbox=dict(facecolor='yellow', alpha=0.5))

#y-axis labelling
#default 
plt.figure()
plt.plot(x,y1)
plt.ylabel('Function')

#Colour
plt.figure()
plt.plot(x,y1)
plt.ylabel('Function', color='g')

#size 
plt.figure()
plt.plot(x,y1)
plt.ylabel('Function', color='Green', fontsize=15)

#Background Box
plt.figure()
plt.plot(x,y1)
plt.ylabel('Function', color='Green', fontsize=15, bbox=dict(facecolor='yellow', alpha=0.5))

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.