Ad Code

What is matplotlib and How to use it (Python).

Matolotlib in Python

matplotlib.pyplot is a collection of functions that make matplotlib work like MATLAB. Each pyplot the function makes some change to a figure.

e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.

A simple program using matplotlib.pyplot
 import matplotlib.pyplot as plt
 plt.plot([1, 3, 8, 4])
 plt.ylabel('some numbers')
 plt.show()

Output:-



Some Graphs types like a bar graph - bar(), pie graph - pie(), scatter graph - scatter(), histogram graph - histogram() etc. 


How to print bar graph - bar()
 import matplotlib.pyplot as plt
 plt.bar([1, 2,3, 4],[1,4,5,2])
 plt.ylabel('some numbers')
 plt.xlabel('numbers')
 plt.title('Bar Graph')
 plt.show()

Output:-



How to print

 pie graph - pie()

 import matplotlib.pyplot as plt
 mylabel=['Apple','Banana','Orange','Mango']
 plt.pie([1, 2,3, 4],labels=mylabel)
 plt.title('Bar Graph')
 plt.show()


Output:- 


Post a Comment

2 Comments

Ad Code