4CP50: Python Programming
Chapter-14
Matplot Library
Prepared By:
Dr. U. K. Jaliya,
Computer Engineering Department,
BVM.
9/30/2022 Python Programming 1
Introduction
Matplotlib is one of the most popular Python packages used
for data visualization.
It is a cross-platform library for making 2D plots from data
in arrays.
Matplotlib and its dependency packages are available in the
form of wheel packages on the standard Python package
repositories and can be installed on Windows, Linux as well
as MacOS systems using the pip package manager.
pip3 install matplotlib
9/30/2022 Turtle and Tkinter Basics 2
Example-1
import [Link] as plt
[Link](1)
[Link]([1,2,3,4],[1,7,3,5])
[Link]()
9/30/2022 Turtle and Tkinter Basics 3
Example-2
import [Link] as plt
import numpy as np
t = [Link](0.0, 2.0, 0.01)
s = 1 + [Link](2*[Link]*t)
[Link](t, s, label='legend')
[Link]('time (s)')
[Link]('voltage (mV)')
[Link]('About as simple as it gets, folks')
[Link](True)
legend = [Link]()
[Link]("[Link]")
[Link]()
9/30/2022 Turtle and Tkinter Basics 4
Example-3
import [Link] as plt
fig = [Link]()
ax = fig.add_subplot()
[Link]([1, 2, 3, 4], [10, 20, 25, 30], color='lightblue', linewidth=3)
[Link]([0.3, 3.8, 1.2, 2.5], [11, 25, 9, 26], color='darkgreen', marker='^')
ax.set_xlim(0.5, 4.5)
[Link]()
9/30/2022 Turtle and Tkinter Basics 5
Example-4
from pylab import *
x = linspace(-3, 3, 30)
print(x)
plot(x, sin(x))
plot(x, cos(x), 'r-')
plot(x, -sin(x), 'g--')
show()
9/30/2022 Turtle and Tkinter Basics 6
9/30/2022 Turtle and Tkinter Basics 7