Unit – V
UNIT V DATA VISUALIZATION
Introduction to Matplotlib, Importing Matplotlib – SciPy - Line plots – Scatter plots – visualizing errors –
density and contour plots – Histograms – legends – colors – subplots – text and annotation – customization
– three-dimensional plotting - Geographic Data with Basemap - Visualization with Seaborn, Data
Visualization Tools.
Sl. No.                                       Part – A (2 MARKS)                             K-Level CO
                                            Questions with Answers
    1. What is the purpose of matplotlib?                                                       K1     CO5
         Matplotlib is a cross-platform, data visualization and graphical plotting library
         for Python and its numerical extension NumPy.
         One of Matplotlib’s most important features is its ability to play well with many
         operating systems and graphics backends.
    2. Write the dual interface of matplotlib?                                                  K1     CO5
        The dual interfaces of matplotlib are: a convenient MATLAB-style state-based
        interface, and a more powerful object-oriented interface.
    3. How to draw a simple line plot using matplotlib?                                         K2     CO5
        import matplotlib.pyplot as plt
        plt.style.use('seaborn- whitegrid')
        import numpy as np
        fig = plt.figure()
        ax = plt.axes()
        x = np.linspace(0, 10, 1000)
        ax.plot(x, np.sin(x))
    4. What functions can be used to draw the scatterplot?                                      K2     CO5
          plt.plot are the functions used to draw the scatter plots.
          Example:
          x = np.linspace(0, 10, 30)
          y = np.sin(x)
          plt.plot(x, y, 'o', color='black');
          Output:
       A second, more powerful method of creating scatter plots is the plt.scatter
       function, which can be used very similarly to the plt.plot function.
       Example:
       plt.scatter(x, y, marker='o')
   5. Write the difference between plot and scatter functions?                                 K2      CO5
      The primary difference of plt.scatter from plt.plot is that it can be used to create
      scatter plots where the properties of each individual point (size, face color, edge
      color, etc.) can be individually controlled or mapped to data.
6. Define contour plot?                                                                   K1   CO5
   Contour plot used to plot three dimensional data into two dimensional data. A
   contour plot can be created with the plt.contour function. It takes three arguments:
   a grid of x values, a grid of y values, and a grid of z values.
7. What are the functions can be used to draw the contour plots?                          K1   CO5
   plt.contour, plt.contourf, and plt.imshow are the functions used to draw the
   contour plots.
   Example:
   x = np.linspace(0, 5, 50)
   y = np.linspace(0, 5, 40)
   X, Y = np.meshgrid(x, y)
   Z=f(X,Y)
   plt.contour(X, Y, Z, colors='black')
   Output:
8.   What is the purpose of using histogram?                                              K1   CO5
     A simple histogram is very useful in understanding a dataset. It is used to
     specify the frequency distributions between two varibales.
     Example:
     plt.style.use('seaborn-white')
     data = np.random.randn(1000)
     plt.hist(data)
9.   Write the source code to draw a simple histogram?                                    K2   CO5
     import numpy as np
     import matplotlib.pyplot as plt
     plt.style.use('seaborn-white')
     data = np.random.randn(1000)
     plt.hist(data)
     Output:
10. How to create a three-dimensional wireframe plot?                                     K2   CO5
    The three-dimensional plots that work on gridded data are wireframes. It take a
    grid of values and project it onto the specified three dimensional surface, and can
    make the resulting three-dimensional forms quite easy to visualize.
    Example:
    fig = plt.figure()
    ax = plt.axes(projection='3d')
    ax.plot_wireframe(X, Y, Z, color='black')
    ax.set_title('wireframe')
    Output:
11. Define surface plot?                                                                  K1   CO5
    A surface plot is like a wireframe plot, but each face of the wireframe is a filled
    polygon. Adding a colormap to the filled polygons can aid perception of the
    topology of the surface being visualized.
    Example:
    ax = plt.axes(projection='3d')
    ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='viridis', edgecolor='none')
    ax.set_title('surface')
    Output:
12. What is Seaborn and why is it used?                                                   K1   CO5
    Seaborn is a open-source Python library built on top of matplotlib. It is used for
    data visualization and exploratory data analysis. Seaborn works easily with
    dataframes and the Pandas library. The graphs created can also be customized
    easily.
    Benefits of Data Visualization:
         Graphs can help us find data trends that are useful in any machine learning
            or forecasting project. Graphs make it easier to explain your data to non-
            technical people.
         Visually attractive graphs can make presentations and reports much more
            appealing to the reader.
   13. What is SciPy?                                                                           K1   CO5
       SciPy is an open-source Python library used for scientific and technical
       computing, built on top of NumPy.
   14. What is the purpose of error bars in data visualization?                                 K1   CO5
       Error bars show variability or uncertainty in the data, often representing standard
       deviation or confidence intervals.
   15. What is a heatmap in Seaborn?                                                            K1   CO5
       A heatmap is a 2D data visualization where individual values are represented as
       colors, commonly used for correlation matrices or density data.
   16. What is the use of colors in data visualization?                                         K1   CO5
       Colors enhance clarity, highlight patterns, and differentiate data groups or variables
       in a plot.
   17. What is text annotation in a Matplotlib plot?                                            K1   CO5
       Text annotation adds descriptive text to plots to highlight or explain specific data
       points.
   18. Write a command to create subplots in Matplotlib.                                        K2   CO5
       plt.subplot(rows, cols, index)
   19. How do you add a legend to a plot in Matplotlib?                                         K2   CO5
       plt.legend()
   20. How do you import the Matplotlib library?                                                K2   CO5
       import matplotlib.pyplot as plt
   21. write a command to create a basic scatter plot and display a plot on a screen            K2   CO5
       using Matplotlib.
       To create scatter plot
       plt.scatter(x, y)
       display a plot on a screen
       plt.show()
   22. What is Basemap in Matplotlib?                                                           K1   CO5
       Basemap is a toolkit for plotting 2D geographic data, allowing map projections,
       coastlines, and location plotting.
                                           Part – B (13 MARKS)
Sl. No.                                        Questions                                    K-Level CO
    1. What is Matplotlib? Explain its significance in data visualization. Describe the two  K3     CO5
        main interfaces used in Matplotlib with examples.
    2. Briefly explain about the line plot and scatter plot.                                 K3     CO5
    3. Explain contour plot and histogram.                                                   K3     CO5
    4. Explain in detail about 3D plotting in Matplotlib with example.                       K3     CO5
    5. How graphical data can be projected using matplotlib? Explain with example.           K3     CO5
    6. Explain the different types of joins in python                                        K3     CO5
    7. Briefly explain about the visualization with seaborn. Give an example working         K3     CO5
        code segment that represents a 2D Kernal density data for any data.
                                             Part – C (15 MARKS)
Sl. No.                                        Questions                                       K-Level CO
    1. Explain the key features of the Matplotlib library used for data visualization in        K4     CO5
        Python. Demonstrate its usage with relevant plot types (e.g., line, scatter,
        histogram, subplot). Analyze the strength and limitations of using Matplotlib in
        comparison with other visualization tools."
    2. How can data be visually represented using scatter plots, line plots, and                K3    CO5
        histograms in Matplotlib? Use appropriate examples and explain how
        customization (colors, labels, titles, etc.) enhances readability.
    3. Discuss various data visualization tools available in Python, including                  K3    CO5
        Matplotlib, Seaborn, and Basemap. Highlight the applications of Basemap in
        plotting geographic data. Provide examples and real-world use cases.
    4. What is error visualization in Matplotlib? Illustrate the use of error bars in           K3    CO5
        scientific and statistical graphs. Explain how they help in data interpretation with
        example code.