Matplotlib is a low level graph plotting library in python that serves as a visualization utility.
Matplotlib is mostly written in python, a few segments are written in C, Objective-C and
Javascript for Platform compatibility.
In [5]: import matplotlib as mp
print(mp.__version__)
3.5.1
PYPLOT
Most of the Matplotlib utilities lies under the pyplot submodule, and are usually imported
under the plt alias:
In [19]: import [Link] as plt
import numpy as np
xp = [Link]([0, 6,8])
yp = [Link]([20, 50,30])
print(xp)
print(yp)
[Link](xp, yp)
[Link]()
[0 6 8]
[20 50 30]
In [20]: [Link](xp, yp, 'o')
[Link]()
In [21]: xp=[Link](1,10,2)
yp=[Link](10,100,20)
print( xp,"\n",yp)
[Link](xp,yp,'o')
[Link]()
[1 3 5 7 9]
[10 30 50 70 90]
By default x_cordinates values are 0,1....(len(y_cordinates)-1)
In [23]: yp = [Link]([3, 8, 1, 10, 5, 7])
[Link](yp)
[Link]()
marker argument : to emphasize each point with a specified
marker
In [25]: [Link](yp, marker = '*')
[Link]()
In [28]: [Link](yp, marker ='D')
[Link]()
linestyle or ls arguments: to change the style of the plotted
line
In [34]: [Link](yp, ls = '-.')
[Link]()
color or c argument : to set the color of the line:
In [38]: [Link](yp, color = '#4CAD55')
[Link]()
In [41]: [Link](yp, color = 'r')
[Link]()
linewidth or lw argument : to change the width of the line
In [43]: [Link](yp, linewidth = '10.5')
[Link]()
MULTIPLE LINES SINGLE PLOT
In [46]: y1p = [Link]([3, 8, 1, 10])
y2p = [Link]([6, 5, 7, 11])
[Link](y1p)
[Link](y2p)
[Link]()
In [47]: x1p = [Link]([0, 1, 2, 3])
y1p = [Link]([3, 8, 1, 10])
x2p = [Link]([0, 1, 2, 3])
y2p = [Link]([6, 2, 7, 11])
[Link](x1p, y1p, x2p, y2p)
[Link]()
LABELS, TITLE & GRIDS
In [60]: maths = [Link]([80, 85, 90, 95, 100, 83,65])
cgpa = [Link]([8,9,9,10,10,9,7])
[Link](cgpa,maths,'o')
[Link]("CGPA")
[Link]("MATHS MARKS")
[Link]("MARKS ANALYZE\n",loc='right')
[Link](c = 'red', ls = '--', lw = 0.5)
[Link]()
SUB-PLOTS
In [62]: #plot 1:
x = [Link]([0, 1, 2, 3])
y = [Link]([3, 8, 1, 10])
#subplot(rows,column,position)
[Link](1, 2, 1)
[Link](x,y)
[Link]("plot1")
#plot 2:
x = [Link]([0, 1, 2, 3])
y = [Link]([10, 20, 30, 40])
[Link](1, 2, 2)
[Link](x,y)
[Link]("plot2")
[Link]()
In [64]: #plot 1:
x = [Link]([0, 1, 2, 3])
y = [Link]([3, 8, 1, 10])
#plot 2:
x = [Link]([0, 1, 2, 3])
y = [Link]([10, 20, 30, 40])
[Link](2, 2, 4)
[Link](x,y)
[Link]("plot2")
[Link]("Main Title")
[Link]()
SCATTER PLOTS
In [65]: x = [Link]([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = [Link]([99,86,87,88,111,86,103,87,94,78,77,85,86])
[Link](x, y)
[Link]()
In [66]: x = [Link]([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = [Link]([99,86,87,88,111,86,103,87,94,78,77,85,86])
[Link](x, y, color = 'RED')
In [68]: x = [Link]([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = [Link]([99,86,87,88,111,86,103,87,94,78,77,85,86])
colors = [Link](["red","green","blue","yellow","pink","black","orange","purple","
[Link](x, y, c=colors)
[Link]()
In [69]: x = [Link]([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = [Link]([99,86,87,88,111,86,103,87,94,78,77,85,86])
colors = [Link]([0, 10, 20, 30, 40, 45, 50, 55, 60, 70, 80, 90, 100])
[Link](x, y, c=colors, cmap='viridis')
[Link]()
[Link]()
BAR PLOTS
In [70]: x = [Link](["A", "B", "C", "D"])
y = [Link]([3, 8, 1, 10])
[Link](x,y)
[Link]()
In [71]: x = [Link](["A", "B", "C", "D"])
y = [Link]([3, 8, 1, 10])
[Link](x, y)
[Link]()
[Link](x)
[Link]()
PIE CHARTS
In [74]: y = [Link]([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
[Link](y, labels = mylabels)
[Link]()
In [79]: y = [Link]([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
myexplode = [0.2, 0.1, 0, 0]
[Link](y, labels = mylabels, explode = myexplode)
[Link](title = "Four Fruits:",loc='right')
[Link]()
In [ ]: