Python package matplotlib for visualization

12 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.39
List Price:  €93.41
You save:  €28.02
£55.92
List Price:  £79.90
You save:  £23.97
CA$96.01
List Price:  CA$137.16
You save:  CA$41.15
A$107.15
List Price:  A$153.08
You save:  A$45.93
S$95.13
List Price:  S$135.90
You save:  S$40.77
HK$547.14
List Price:  HK$781.66
You save:  HK$234.52
CHF 63.86
List Price:  CHF 91.23
You save:  CHF 27.37
NOK kr775.40
List Price:  NOK kr1,107.76
You save:  NOK kr332.36
DKK kr487.78
List Price:  DKK kr696.86
You save:  DKK kr209.07
NZ$118.01
List Price:  NZ$168.60
You save:  NZ$50.58
د.إ257.06
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,680.49
List Price:  ৳10,972.60
You save:  ৳3,292.11
₹5,842.03
List Price:  ₹8,346.11
You save:  ₹2,504.08
RM332.86
List Price:  RM475.54
You save:  RM142.67
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,491.96
List Price:  ₨27,846.85
You save:  ₨8,354.89
฿2,586.09
List Price:  ฿3,694.58
You save:  ฿1,108.48
₺2,265.39
List Price:  ₺3,236.41
You save:  ₺971.02
B$363.53
List Price:  B$519.35
You save:  B$155.82
R1,302.64
List Price:  R1,861
You save:  R558.35
Лв127.90
List Price:  Лв182.73
You save:  Лв54.82
₩96,270.48
List Price:  ₩137,535.16
You save:  ₩41,264.67
₪262.29
List Price:  ₪374.71
You save:  ₪112.42
₱4,033.94
List Price:  ₱5,763.02
You save:  ₱1,729.07
¥10,867.12
List Price:  ¥15,525.12
You save:  ¥4,658
MX$1,187.12
List Price:  MX$1,695.96
You save:  MX$508.84
QR254.93
List Price:  QR364.20
You save:  QR109.27
P994.08
List Price:  P1,420.18
You save:  P426.09
KSh9,360.69
List Price:  KSh13,372.99
You save:  KSh4,012.30
E£3,358.63
List Price:  E£4,798.26
You save:  E£1,439.62
ብር4,003.77
List Price:  ብር5,719.92
You save:  ብር1,716.15
Kz58,546.63
List Price:  Kz83,641.63
You save:  Kz25,095
CLP$67,216.99
List Price:  CLP$96,028.39
You save:  CLP$28,811.40
CN¥506.70
List Price:  CN¥723.89
You save:  CN¥217.19
RD$4,073.53
List Price:  RD$5,819.58
You save:  RD$1,746.04
DA9,418.34
List Price:  DA13,455.35
You save:  DA4,037.01
FJ$158.31
List Price:  FJ$226.17
You save:  FJ$67.86
Q543.96
List Price:  Q777.12
You save:  Q233.16
GY$14,650.29
List Price:  GY$20,929.88
You save:  GY$6,279.59
ISK kr9,815.39
List Price:  ISK kr14,022.59
You save:  ISK kr4,207.20
DH707.71
List Price:  DH1,011.06
You save:  DH303.35
L1,237.78
List Price:  L1,768.33
You save:  L530.55
ден4,025.24
List Price:  ден5,750.59
You save:  ден1,725.35
MOP$563.96
List Price:  MOP$805.69
You save:  MOP$241.73
N$1,304.33
List Price:  N$1,863.42
You save:  N$559.08
C$2,570.38
List Price:  C$3,672.13
You save:  C$1,101.75
रु9,397.27
List Price:  रु13,425.24
You save:  रु4,027.97
S/263.43
List Price:  S/376.35
You save:  S/112.91
K270.11
List Price:  K385.89
You save:  K115.77
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,873.89
List Price:  ZK2,677.10
You save:  ZK803.21
L325.37
List Price:  L464.84
You save:  L139.46
Kč1,643.47
List Price:  Kč2,347.91
You save:  Kč704.44
Ft25,458.03
List Price:  Ft36,370.18
You save:  Ft10,912.14
SEK kr764.90
List Price:  SEK kr1,092.76
You save:  SEK kr327.86
ARS$61,327.27
List Price:  ARS$87,614.14
You save:  ARS$26,286.87
Bs483.57
List Price:  Bs690.85
You save:  Bs207.27
COP$273,218.78
List Price:  COP$390,329.27
You save:  COP$117,110.49
₡35,710.66
List Price:  ₡51,017.42
You save:  ₡15,306.75
L1,733.65
List Price:  L2,476.75
You save:  L743.09
₲524,442.73
List Price:  ₲749,236.02
You save:  ₲224,793.28
$U2,683.09
List Price:  $U3,833.15
You save:  $U1,150.06
zł283.24
List Price:  zł404.64
You save:  zł121.40
Already have an account? Log In

Transcript

Hello everyone, welcome to the course of machine learning with Python. In this particular lecture video, we will introduce matplotlib which is a very good plotting library in Python. So it is used for graphical plotting, as well as for data visualization. So few properties of matplotlib library matplotlib is widely used library in Python for data visualization, it provides very useful and easy to use API for MATLAB like plotting one of the metric lips most important feature is its ability to play with with many operating system and graphics backends so it has a high portability like NumPy It is also very much mature, stable and under continuous development. So how to use matplotlib library So one has to install matplotlib library first in order to use it. Okay, so you have to go to Anaconda prompt and type pip install matplotlib to install matplotlib in your system.

Now, if you were using Anaconda distribution, then you didn't have to install it first. Because Anaconda comes with matplotlib pre installed so you can skip the step of installing matplotlib library as described in the first day, how to use the library functions inside matplotlib Why has to import it first we shall see the use of each sub module which is named pi plot in details Okay, so matplotlib has many sub modules or sub packages. So one of them is called a PI plot. So we will use PI plot extensively in only chat, so please visit the website which is mentioned over here for complete documentation of Mcluckie. Now we will see how to use matplotlib in certain Jupiter notebook environment. So let's open our Jupiter notebook.

So, this is the Jupiter notebook file I have created for my demonstration of the matplotlib library. So the official metrically website is this one and under this you can find the pipeline API website which is also mentioned over here now you should input in history libraries. Now in order to demonstrate how the matplotlib works I have to create some data in order to plot it okay. So for that I have used NumPy library. So I have imported NumPy library as in in P. Similarly, I have imported matplotlib.pi plot as PLT Okay. So, what is pi plot by plot is a sub package which comes under matplotlib package.

So that is well matplotlib.pi plot okay now here is a magic comment called passive matplotlib space inline So, as you as it is mentioned over here matplotlib in line is the magic comment for the scatter plot inside the Jupiter notebook okay now, depending on the version of the Jupiter notebook, one may run this comment or one may not okay for the latest version of the Jupiter notebook. This particular command is not required, it will default to plot it, it will make static plots. Okay, now for interactive plots one can also use the magic command for parsing matplotlib space notebook. Okay, so let's go ahead and run this particular cell using Shift Enter. It will take some time to import this libraries into a notebook file. So let's create the data Okay.

Now in order to create the data what I have used I have used NP dot linspace. So I am creating thousand data points between 0245 so np.pi is basically the PI number. Okay. 3.14159 So between zero to four pi i am creating thousand data points okay now if I go ahead and touch extra ship it has returned thousand that means x contains thousand data points okay now y equals to NP dot sign within bracket x okay so this inferior sign is in Universal function as it is operated on a vector or an any x okay it will return a similar dimensional vector or any y okay now if I go ahead and type Wilder ship as you can see he has also returned thousand comma the same shape as x that means y is also of the similar shape as a political disease why not contains the sinusoidal values of x that means, let's say if zero is zero then y zero will be sine of zero okay understood.

Now let's go ahead and plot this okay. So here so many comments are there so PLT dot figure within bracket I am giving an argument fixed size equal to six comma four so fixed size actually determine how big or how small my finger will be. So six comma four means it will have for each week and six inch length. Okay, now PLT dot plot, we can bracket x comma y comma, that means, along the x axis, I'll be plotting x and y axis I'll be plotting y, y is nothing more sine of x and the color of the plot will be red. That is why the I have passed the code name of red, which is quote unquote, up okay. Now PLT dot grid will actually create the grid lines in the plot, okay.

So similarly, we have created plot dot x level within bracket, quote unquote capital X. So the x on the horizontal level will be x and the vertical level will be scientists as mentioned in the plot dot y level, okay. And I have mentioned the title of the product scientists, nurses, so let's see, how does it work fine. Okay, so as you have seen, so, the plot has 16 inch length and four inch width, okay, now it has, let's say I do not want to Use this product. Let's see how does it work okay. So as you have seen that if I will not use plotter grip, so there will not be any grid Mark throughout the plot.

Okay, now let's go ahead and uncomment this okay and other cell again. So now you can see that there is a grid land for now we can also use this particular function plot dot PLT for plotting multiple lines to get multiple land plots together. So let's say a y one equals to NP dot sine of x. So y contains the silencer values of x and y two contains the precise values of x. Okay, if I plot this, let's see what happens. Okay, so I'll explain this.

So PLT dot plot within bracket x comma y one so I am first plotting y one versus x and second I am plotting y two versus x. In order to differentiate the plot I have mentioned the color of the first plot as blue and the color of the second plot as red and I have also labeled The plots as first plot assignment the second plot as cosine now I have turned on the grid and I have also mentioned PLT dot legend Okay, so PLT dot legend will place a legend inside my plot that is this blue line basically indicates sign and the red line will basically indicates cause so if you have multiple plots, which is always a good idea to place the legend okay. Similarly, I have labeled the x axis x and y axes as sign or cost value of x, okay? And I have given a title, my underscore plus.

Okay, so as you can see, the plot has been created, okay, the figure size is 10 comma six. So the properties have been inch in wheat and six inches in height, okay, or we can say 10 inches less than six inches in width, fine. Okay, now let's see a few more examples. So let's say I want to plot y one versus while two, a scaled version of y one was a scaled version of y two, and let's see how does it work. So as you can see, it is plotting an ellipse fine. Now we can use sub notes to add more plots inside the same figure, okay.

So, let's say I have four values like y one y two y two y four y one contains a sinusoidal values of x, y two cos contains the cosine Seidel values of x, y two contains the natural logarithm of X and Y for contesta exponential values of x now what is it is thousand data points between one to 10 Okay. Similarly, I have mentioned my finger size is eight by eight okay and PLT dot issue p title. So, this is basically the super title which basically assigns the title to the entire figure. Similarly, inside each subplot I have also mentioned PLT dot title. So, this is basically individual subtitle you can say for the subclass. Now, what is subplots So, you can see there are three arguments two comma two comma one.

So, the first one is basically number of rows. second argument is number of columns. And the third argument is were in this breed of row by column mind Particular support will be placed. So, let me explain it again. So, this is two comma two that means there will be two rows and two columns and my this subplot will be placed at the first position of this particular plot okay. Similarly, I have mentioned subplot two comma two comma two and two comma two comma three and to go to go for that means in the first part of the supply, I'll be plotting signings versus in the second part I will be plotting costs versus takes in the top part of plotting love versus x and in the fourth part on plotting the power x versus x Okay, so let's go ahead and now this particular set okay.

So, as I can see there is a two by two plotting okay in the first one I have not assigned x which is x, the second one I have plotted positive versus x in the third one I have plotted logging versus x and in the fourth one I have predict exponential is that is e to the power x versus x. Okay, so this is the beauty of subplots fine. Now let's go ahead and find something called a scatter plot. So let's say it is basically started random numbers. Similarly, y is also some random numbers physically taken from the NumPy library NP dot random. Okay, now let's go ahead and plot x versus y.

Okay, so, this will create a matplotlib population object. Now, if you want to don't want to print this particular comment that is printed over here, you can always uncomment it using the semicolon okay. So, if you go ahead and on this, you can see that no comment has been printed over here fine. Now, it will plot x comma y that means each tupple represents a coordinate in the explain plane. So it will be plotting the points that is noted by the XY coordinates, okay? And how many such points will be there, they'll lose points.

So this is basically the scatter plot. Now let's go ahead and see what is the bar plot. So I have created some values 1015 519 2270 and I have used bar plot where x is basically the numbers ranging from one to seven. So that means Excluding seven that is 123456 and the height of this bar plot will be nothing but my values defined over here. Now, let's go ahead and on this particular sin and see that in the first position the value is 10 the second position of Halloween is 15. So, I have having a visualization of this entire added this is by using the power block okay good now we can also use different x values okay for example, let's say I have used x values D one D two D three d four D five D six.

Similarly, if I ran this cell, you can see that the corresponding x values has been changed and also the colors has been changed why because I have mentioned color equals to R over here. Now the default color is blue if you do not mention any color, it will automatically take blue and if you mentioned some color it will take that fine okay. Similarly we can have horizontal bar plots. Now we shall see a plot called histogram plot Okay, so I have created 100 normally distributed random number using the function called then In which is mentioned under NP dot random library, okay, now I have plotted these numbers in 10 beats, okay. And I have mentioned its color equals to k k means black. Okay, now let's go ahead and run this particular cell.

As we can see, this is basically the histogram plot of one particular batch file. Now let's go ahead and increase the numbers and see what happens okay. So now we can see there is how not normally distributed pattern over here, we can go ahead and create more values. So let's say this is basically 100,000 values are there and I have decided that the number of means should be 100 fine. If you run this particular comment, you can see a nice bell curve like pattern over here fine. So this is a very good way to describe the underlying probability density function.

Now we can also plot three dimensional plots using matplotlib library. So for that we have to import from MPL underscore toolkits dot M plot 3d input access 3d. Okay, so I want to exclude it by yourself. The Notebook has been provided just go and play around with it. Okay and you will see there are so many ways to play around with the different data visualization techniques that matplotlib offers. In the next video, we will see how to use pandas library for data manipulation.

Okay, so see you in the next lecture. Thank you.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.