Page 295 - Ai_C10_Flipbook
P. 295

Some types of graphs that we can make with this package are listed below:











                        Histogram            Pie Plot           Box Plot           Scatter Plot           Line Graph


                 Installing Matplotlib

                    • To install it using pip:
                                                       python -m pip install -U pip

                                                   python -m pip install -U matplotlib
                   Or
                                                          pip install matplotlib

                   For plotting using Matplotlib, we need to import its Pyplot module as follows:
                     import matplotlib.pyplot as plt

                 The pyplot module of matplotlib has built in methods which help in designing a graph with all features. Few of
                 the functions are explained below:

                    • The plot(x,y,marker) function is used to create a box-like figure  where the actual graph is plotted.  To plot x axis
                   versus y axis, we write plt.plot(x,y). By default, it plots a line graph.
                    • plt.plot(kind='line')will make a line graph. We can have the following values of the kind parameter to change the
                   type of the graph needed to make.
                   Arguments accepted by kind for different plots

                            kind =                         Plot type

                            line                           Line plot (default)
                            bar                            Vertical bar plot

                            barh                           Horizontal bar plot
                            hist                           Histogram

                            box                            Boxplot
                            area                           Area plot

                            pie                            Pie plot
                            scatter                        Scatter plot

                 List of Pyplot functions to plot different charts and customise plots
                    • The scatter(x, y) function will plot a scatter graph.

                    • The show() function will display the figure created.
                    • The savefig(filename) function can be used to save the figure in your computer.

                    • The xlabel(Text) function is used to give label to x axis.

                                                                                    Advance Python (Practical)  293
   290   291   292   293   294   295   296   297   298   299   300