Page 467 - AI Ver 3.0 class 10_Flipbook
P. 467

Plotting a Scatter Chart

                 Scatter plots use dots to display values from two variables in a graph. It is used to plot data which has no
                 continuity(non-continuous data). This allows us to see if there is any relationship or correlation between the two
                 variables.

                 Matplotlib uses a built-in function - scatter() to create scatterplots.
                 Example:

                    [1]:  import matplotlib.pyplot as plt
                          marks1=[31,34,36,42,40,23,39]
                          marks2 = [34,45,23,44,12,16,35]
                          plt.scatter(marks1, marks2, c='red')
                          plt.title('Scatter plot')
                          plt.xlabel('marks 1')
                          plt.ylabel('makrs 2')
                          plt.show()



















                 Plotting a Box Plot(Whisker Plot)                                 lower                     lower
                                                                                 quartile Q1   median      quartile Q3
                 SIt represents the summary of the set of data values where a
                 box is created for each having properties like minimum, first   min                                 max
                 quartile, median, third quartile and maximum. A vertical line   whisker                        whisker
                 goes through the box at the median. Here x-axis denotes
                 the data to be plotted while the y-axis shows the frequency
                 distribution.                                                          interquartile range (IQR)
                 Box plots are used to plot outliers and these outliers are plotted outside the graph as dots or circles since they
                 do not belong to the range of data and are part of the graph for visualisation.
                 Matplotlib uses a built-in function -boxplot () to create box plots.

                 Example:

                    [1]:  import matplotlib.pyplot as plt
                          eng = [82,76,24,40,67,62,78,67,72,82]
                          maths=[62,5,32,96,95,90,95,15,71,11]
                          science=[68,86,19,49,15,16,16,75,65,31]
                          sst=[98,10,87,29,72,16,23,72,75,30]
                          box_plot_data=[eng,maths,science,sst]
                          plt.xticks([1, 2, 3, 4], ["Eng", "Maths", "Science", "SSt"],
                          rotation=10)
                          plt.boxplot(box_plot_data)
                          plt.title('Box Plot')
                          plt.xlabel('Subjects')
                          plt.ylabel('Marks')
                          plt.show()

                                                                                    Advance Python (Practical)  465
   462   463   464   465   466   467   468   469   470   471   472