Page 132 - Informatics_Practices_Fliipbook_Class12
P. 132

plt.title(): This function is used to set the title for the plot. It takes a string as an argument thatdenotes the title
                 of the graph.
              Some other common functions used for plotting graphs through Matplotlib:

                                   Functions                        Purpose

                            xlabel()              to write label name for x-axis
                            ylabel()              to write label name for y-axis
                            title()               to write title for the plot
                            legend()              to show legends
                            show()                to view the plot
                            savefig()             To save the plot as .png or .pdf at the desired location

           5.  What is the purpose of a legend?
         Ans.   The purpose of a legend in Matplotlib is to provide an explanation or key for the different elements (e.g., lines, markers,
              colors) present in a plot. It helps users understand the meaning of each component in the graph, making the visualization
              more informative.

           6.  Define Pandas visualisation.
         Ans.   Pandas visualization refers to the built-in data visualization capabilities provided by the Pandas library in Python. It allows
              users to create various types of plots, charts, and graphs directly from Pandas data structures, such as DataFrames and
              Series, making it convenient for data analysis and exploration.
           7.  What is open data? Name any two websites from which we can download open data.
         Ans.  Refer to 8.6 Open Data
           8.  Give an example of data comparison where we can use the scatter plot.
         Ans.  Refer to 3.1.3 Scatter Plot
           9.  Name the plot which displays the statistical summary.

         Ans.  The plot that displays the statistical summary in Matplotlib is called a "box plot" or "box-and-whisker plot."
              Note: Give appropriate title, set xlabel and ylabel while attempting the following questions.
          10.  Plot the following data using a line plot:
                      Day          1        2       3        4        5        6        7
                   Tickets sold  2000     2800     3000     2500    2300     2500     1000
              a.  Before displaying the plot display "Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday" inplace of Day 1,
                 2, 3, 4, 5, 6, 7
              b.  Change the color of the line to 'Magenta'.

         Ans.  import matplotlib.pyplot as plt
              # Data
              days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
              tickets_sold = [2000, 2800, 3000, 2500, 2300, 2500, 1000]
              # Plotting
              plt.plot(days, tickets_sold, color='magenta', marker='o', linestyle='-', linewidth=2,
              markersize=8)
              # Adding labels and title
              plt.xlabel('Day')
              plt.ylabel('Tickets Sold')
              plt.title('Tickets Sold Each Day')






          118  Touchpad Informatics Practices-XII
   127   128   129   130   131   132   133   134   135   136   137