Welcome back. In this particular video we are talking about most important questions from plotting with PyPlot or we can say data visualization. Let's discuss all the questions one by one which I think will definitely help you in your preparation.
Now the question number one is saying that what is the purpose of matplotlib library. We all know that matplotlib library is basically a library of python which basically used to create 2d graphics. When we talk about 2D graphics means we are talking about charts.
Soo we can say the purpose of matplotlib library is to generate graphs. The matplotlib is a Python package that provides many functionality for 2D plotting in various forms. Now we all know that when we talk about Python package which is made up of different interfaces or we can say made up of modules. Like in this there is a very famous module which we all know is Pyplot. Soo this is how we can write answer of this question.
Let's move to the next one. Here it is saying that name the function you will use to create line chart, bar chart or you can say horizontal bar chart. We all know that if you want to make line chart then the method we use for this is your plot.
Soo for bar chart we use bar method and for horizontal bar chart we can use this bar h method. In the sense these are the different methods we can use. Let's move to the next question now.
Here it is saying that write a Python program to display a bar chart of the number of students in the class. Soample data is given. These are the class and these are the students. For this we have to prepare a bar chart.
Bar chart means we have to prepare a column chart. For this, the code we will write, obviously, first of all, we need to import matplotlib library and especially its pyplot module. We have to import it. Soo we should write matplotlib library.
plotlib.pyplot and after this we should write or take its object by name of say plt. You can take any name here. Plt is not necessary but because it is in practice we will take it.
After this obviously we have to create two lists. One we will make in the name of class in which we will mention these different classes. One thing you should keep in mind is that the class itself is a class.
Soo, we will make a class of class. Soo, we will make Soo it's better to spell it as single So. I will delete it and write it.
Soo I have taken this C L A So or you can take any name of it. Soo I will complete it. And in the same way, I will prepare the list of other strengths here.
And after this, obviously we will call the bar method of PLT in which we will first pass the class because it is my The representation of x-axis will be like 6, 7, 8, 9, 10, 11. And the values, in the sense, the strength will be displayed in our y-axis. Therefore, we will use the strength as the second argument. And after this, you can execute this code.
But if you want to display the chart, then we have to take another method by the name of this show. When you execute this entire code, then you will see, in this way, the column chart will appear on your screen. Let me execute it and show you. Soo as you can see in your screen, this is my code which I just discussed with you.
Now let's run it once. Soo you can see here, this is our bar chart which we have just prepared according to our question. These are the classes and these are the strengths. Here I have not included 11th and 12th.
But if you want, you can include those values too. Soo you will get 11th and 12th classes too. Let's see the next question.
Here it is saying that The command used to give heading of the paragraph is called what? Heading means displaying the title of any chart. And the method we use for this is your plt.title.
Come, let me practically execute this and show you. Let's take the example of the bar chart we prepared in the previous question. Soo this is our example.
Soo if I write plt.title and inside this I write bar chart. And after this if you execute this code then you see what happens. Soo you can see we have put the heading of our chart here.
That is my title. Soo this is how we can get the answer. Let's move to the next question now.
Here it is asking using Python matplotlib dash can be used to count how many values fall in each interval. Now here it is asking which of these plots have how many values fall in each interval. we can count it.
The example of this is actually a histogram because a histogram is basically a We use it for the range of values or for the continuous form data. And the bin we set, the range we set, how many values are falling in it, we display it in the bar form with the help of this histogram. Soo the correct answer is histogram for this question. Maybe it can be included in your syllabus or not when you are watching, so make sure. Let's move to the next question now.
Here it is saying out of the following which function cannot be used for customization of chart in python. Meaning if you are making any chart, then customization means that you modify its x-axis, y-axis or the bars or data series in it. Like naming x-axis, y-axis, giving title, changing the color of bars. In that sense, we use x-label, we also use title, legend.
which we use to represent the data series so we use these three no function is available in the name of color method so the correct answer is option number B move to the next question here it is saying that write a python program to plot a line chart based on given data to depict the changing weekly average temperature in Delhi for 4 weeks so here it is week and here it is average temperature Now we have to write a code on its basis. Soo obviously first of all we will import matplotlib library. I will write that code here. After this we will ready both these lists. After creating list, obviously because we have to ready line chart here.
Soo the method we will use here is my plot method. In x axis we will represent week and in y axis we will take average temperature. Soo we will simply write avg underscore temperature.
And after this, you will display this code by showing plt.show. In the sense, you will display the chart. As soon as you execute this code, you will get the answer. Come, let's execute this in Python as well. Soo as you can see in your screen, this is our Python code which we have just prepared for this question.
Now let's run it. Soo now you can see this is how our line chart is being displayed. Soo this was about this question.
Let's see the next question. Observe the chart and identify the location of legend. You can see the legend is displayed here. If you want to know its position, in the sense, when you create this chart, and when you write plt.legend, and execute this code, by default, the legend is displayed at the upper right corner.
Soince it is the upper left position, you can present it in two ways. Either you write plt.legend, and write LOC equal to upper left space and write upper left either this code will display the legend here or on this legend, you have to give the position of 2 on the LOC you take so when you do 2, it will also display here so the correct answer would be LOC equal to 2 I hope you understand the answer to this question If you type loc="1", it will display in the upper right corner. Let's move ahead.
It is asking that how does Python supports data visualization? We all know that data visualization is the most popular in Python. And the library we use for this is your matplotlib. As we have seen, it has different modules, the most popular of which is pyplot. Soo, Python uses libraries to support data visualization somewhere and the most popular one is your matplotlib.
Soo, this is how we can give the answer of this question. Move to the next question now. Here it is saying that look at the following graph and write appropriate code to obtain this output. We have to write code to make this chart.
Soo, first of all, you import matplotlib. Now the important thing here is that the x-axis you have to see and the y-axis. Generally when you prepare any line chart, the graph that is drawn in it is displayed in this sequence.
But in this chart you are seeing, the data is coming in this way, in the sense that the line will never be reverted. This means that the value of the x-axis here, we have to We have to take the value of this y-axis and this x-axis in y. Means I write this code here. As I took in x, I first make the list ready.
We will use these values in x. Soo it is starting from 1. Soo what I do, I can take this to 1. I am taking 1 because the first point is here. The second point is here. The third point is here and the fourth point is here. Soo we can say 1, 2, 3 and 4. After this, we will take these values in the y-axis.
Soo in the y-axis, the first value for 1 is 225 around. And the second value is 425. Soo we can take this to 425. The third value is exactly 300. And the fourth value is 150. Soo this is how we can get this data. Soo this is the main of this program. And since we are plotting a line chart, we will simply write plt.plot And as I told you, since we have put the values in X, 1, 2, 3, 4 and Y here Soo we will first take Y as Y represents the X axis and X represents the Y axis And when you show plt.plot, this code will make this chart for you Let's execute this on Python Soo as you can see in your screen, this is the code which I have discussed with you.
Let's run it. And now you can notice that the chart which you were looking at in the question, the same chart is being displayed here. Soo overall in the sense we can say, the correct code of this question will be this. Let's discuss the next question. Here it is asking that why is the following code is not producing any result?
Why it is giving errors? Here it is saying that we have included all the libraries in this code. Soo this is our code.
A is there, B is there and matplotlib.piplot.plot is there. Now here we have used the range method. There is an interval of 12. Soo the first value will be 10. And after that next will be 22. Then your 36 and next would be your 48. But when you see this value, then first of all it will be 90 and there is an interval of 20. Soo obviously this will be your 110, then 130, then 150, 170 and then your 190. Soo, you can see that the shapes of both are different. These are total 4 elements and here you can see total 6 elements. Soo, because the shape of both the lists will be different.
And because of being different, when it will try to plot, it will produce error. Because by the rule, when you do any data visualization or plotting, then the shape of the data you provide in that list or data should be same. Soo, this is why This will produce an error and the answer I gave you that because of the different shapes, this will not be a plot. This is the reason.
Soo you can see here I have written its answer in this way. You can see it by pausing the screen. For now, I will move to the next question. Here it is saying that what is the role of legend in chart and graph?
Soo the purpose of chart and graph in legend is this. Like you prepare a bar chart. and you have represented multiple data in this way to identify these different data series we use or take help of legents which tells that this is A list, I mean data series and this is B data series so the purpose of legents as I said is color or mark that helps in identifying different data series plotted in a chart And you can see this is our legend for this particular chart.
Soo let's move to the next question now. Give an example of data comparison where we can use column chart. There can be many examples of this.
The example I have mentioned here is that suppose that all the children in your class, all the marks of those children, you want to do a comparison of those marks as you can see in this chart. and we want to find out who is the highest scorer and who is the lowest scorer then we can use column chart in such a situation where we compare the data so this is how we can get the answer let's move to the next question here it is saying that the score of 4 cricket team in 4 matches is available to you write program to plot horizontal bar chart with the following you have to display legend in bottom right corner The level of the Category axis should match and the level of the Value axis should be Runs. You can take the score of the cricket team and the number of matches yourself.
Because we are talking about 4 matches here, so first of all you will prepare a list in the name of the match where we present 4 matches in this way. Soecond, you will prepare a list in the name of the score where you can provide the values you want to give. Soay for example 270. and after that we have to import matplotlib library and after that when you will prepare bar chart we are talking about horizontal bar chart so we will write bar h In which we will pass the match in X axis and the score will be displayed in Y axis.
Soo this will be like this. And since we have to display legend on bottom right corner, so we will take this plt.legend where you will do loc="4". If this 4 does not work, then you can write loc="bottom right". You will not face any problem.
This is also a way to use it. And as I said, the title of the category axis is xLabel. Soo I will delete it and write it again.
We have passed the match in it. And in the same way, you will take the plt.yLabel. And you will pass the score in it as a string that you want to display.
And after that plt.show. This way your code will be ready for this question. You will get the result when you execute it. Let's execute it on Python. Soo as you can see in your screen, this is my Python code for this question.
Which we have just discussed. Let's run it. Soo as you can see in your screen, the chart of the question will be displayed like this.
Here is the score and match. Let's discuss the next question. Here it is asking that, A list namely temperature contains average temperature for 7 days of last week. Which chart type will you plot for the same and why?
You have the list of average temperature. Now if you want to visualize it, then which chart will you take and what is its purpose? Soo see in this you can give answer in line chart and column chart.
There will be no problem anywhere. But ideally I would suggest you to use line chart in this. Because with the help of line chart you can... Over the days, we will get the variation of the temperature, the trend. Soo, to find out the data pattern or data trend, we use the line chart.
In the sense, the answer to this question, as I have written here, we will use line chart to depict the changes in temperature during days interval, which will help us to find the data trend. Let's discuss the next question. Now, here it is saying that Raj has written following code to create a bar chart.
here it is imported as weekdays and here it is sale plt.bar weekdays comma sale but when it is executing this code then it is not displaying the result in the sense the chart is not displaying so what can be the reason so obviously if you pay attention to this code we have not used plt.show method in this so the correct answer would be that it has to include the show method here let's see the next question Here it is saying that the command to install matplotlib library in python is we all know that it is simply pip install and after that you write matplotlib and this library will be installed. Soo the correct answer is option number D. Let's move to the next one. Here it is saying if the extension of file name is not given in save figure then the file is saved with the dash extension. Soo the correct answer is your.jpg.
Let's move to the next one. Here it is asking that which of the following is incorrect regarding data visualization. The first is saying that data visualization can be done using matplotlib library. Soo this is absolutely correct.
Visualizing large and complex data does not produce effective result. Which is absolutely wrong because we represent large and complex data in our graph form so that we can take decisions easily. Soo, the correct answer is option B. But, let us see the next options also. Data visualization is immensely useful in data analysis.
Absolutely right. Decision maker use data visualization to understand business problem easily and build strategies. Which is again correct.
Soo, the correct answer is option number B for this question. Soo, overall these were the 25 most important questions related to pipe plot or data visualization. Which I think will definitely help you for further preparation. whether it is related to Informatics Practices or Pi Plot.
With this hope, let's end today's session here. Soee you in the next session with a new chapter, new solution, new concept. Till then keep practicing and keep learning and do keep watching my channel.
Thank you for watching this video.