Data Visualization
Data visualization is the process of converting complex data into
graphical formats such as charts, graphs, and maps. It allows users
to understand patterns, trends, and outliers in large datasets
quickly and clearly.
By transforming data into visual elements, data visualization
helps in making data more accessible and easier to interpret,
allowing for more informed decisions and insights
Dept. of CS&E, MSRIT
Data Visualization
Dept. of CS&E, MSRIT
Best Library Based on Kind of Data
Library Best for Data That Is
1. Matplotlib Raw, numerical, experimental
2. Seaborn Tabular, statistical
3. Plotly Interactive, multidimensional
4. Bokeh Streaming, large-scale
5. Altair Clean, aggregated
6. Pygal Small, simple, web-ready
Dept. of CS&E, MSRIT
Features of Data Visualization
• Simplifies Complex Data: Transforms complex datasets into
easy-to-understand visuals.
• Identifies Patterns: Helps spot trends and patterns that might
not be obvious in raw data.
• Improves Decision-Making: Provides visual clarity, helping
decision-makers make informed choices faster.
• Highlights Key Insights: Allows for the emphasis of important
trends, outliers, and relationships.
• Interactive: Many visualizations allow for user interaction,
enabling deeper exploration of data.
Dept. of CS&E, MSRIT
Example 1: Plotting with Matplotlib
import [Link] as plt
import numpy as np
days = [Link](1, 31)
temperature = 25 + [Link]([Link](30))
# simulated temperature trend
[Link](days, temperature, marker='s', linestyle='--')
[Link]("Simulated Daily Temperature")
[Link]("Day")
[Link]("Temperature (°C)")
[Link](True)
[Link]()
Dept. of CS&E, MSRIT
Example 1: Plotting with Matplotlib
Dept. of CS&E, MSRIT
Data Visualization with Matplotlib
Matplotlib is a powerful and versatile open-source plotting library
for Python, designed to help users visualize data in a variety of
formats. Developed by John D. Hunter in 2003, it enables users to
graphically represent data, facilitating easier analysis and
understanding.
To install this type the below command in the terminal.
pip install matplotlib
import [Link] as plt
x = [0, 1, 2, 3, 4]
y = [0, 1, 4, 9, 16]
[Link](x, y)
[Link]()
Dept. of CS&E, MSRIT
Data Visualization with Matplotlib
Dept. of CS&E, MSRIT
Matplotlib Pyplot
Pyplot is a module within Matplotlib that provides a MATLAB-like
interface for making plots. It simplifies the process of adding plot
elements such as lines, images, and text to the axes of the current
figure.
Steps to Use Pyplot:
• Import Matplotlib: Start by importing [Link] as plt.
• Create Data: Prepare your data in the form of lists or arrays.
• Plot Data: Use [Link]() to create the plot.
• Customize Plot: Add titles, labels, and other elements using
methods like [Link](), [Link](), and [Link]().
• Display Plot: Use [Link]() to display the plot.
Dept. of CS&E, MSRIT
Different Types of Plots in Matplotlib
Matplotlib offers a wide range of plot types to suit various data
visualization needs. Here are some of the most commonly used
types of plots in Matplotlib:
1. Line Graph
2. Bar Chart
3. Histogram
4. Scatter Plot
5. Pie Chart
6. 3D Plot
Dept. of CS&E, MSRIT
Key Features of Matplotlib
• Versatile Plotting: Create a wide variety of visualizations,
including line plots, scatter plots, bar charts, and histograms.
• Extensive Customization: Control every aspect of your plots,
from colors and markers to labels and annotations.
• Seamless Integration with NumPy: Effortlessly plot data
arrays directly, enhancing data manipulation capabilities.
• High-Quality Graphics: Generate publication-ready plots with
precise control over aesthetics.
• Cross-Platform Compatibility: Use Matplotlib on Windows,
macOS, and Linux without issues.
• Interactive Visualizations: Engage with your data dynamically
through interactive plotting features.
Dept. of CS&E, MSRIT
Data Visualization with Seaborn
Seaborn is a popular Python library for creating attractive
statistical visualizations. Built on Matplotlib and
integrated with Pandas, it simplifies complex plots like
line charts, heatmaps and violin plots with minimal code.
types of plots in Matplotlib:
1. Line Plot
2. Scatter Plot
3. Box Plot
4. Violin Plot
5. Swarm Plot
6. Bar Plot and many more…
Dept. of CS&E, MSRIT
Data Visualization with Seaborn
Line Plot
>>[Link](x=None, y=None, data=None)
Dept. of CS&E, MSRIT
Data Visualization with Seaborn
Scatter Plot
>>[Link](x=None, y=None, data=None)
Dept. of CS&E, MSRIT
Data Visualization with Seaborn
Box plot
>>[Link](x=None, y=None, hue=None, data=None)
Dept. of CS&E, MSRIT
Data Visualization with Seaborn
Violin Plot
>>[Link](x=None, y=None, hue=None, data=None)
Dept. of CS&E, MSRIT
Data Visualization with Seaborn
Swarn Plot
>>[Link](x=None, y=None, hue=None, data=None)
Dept. of CS&E, MSRIT
Data Visualization with Seaborn
Bar Plot
>>[Link](x=None, y=None, hue=None, data=None)
Dept. of CS&E, MSRIT
Assignment
Write a Python program to analyze student exam scores with branch information:
1. Install and use Faker library to generate synthetic data
2. Generate 100 student records with:
• Unique student IDs (format: 1MS25CSE001, 1MS25CNE001, etc.)
• Branch assignment (CSE or CNE)
• Random exam scores (0-100) using Faker
3. Categorize each score using list comprehension with if-else:
• "Fail" if score < 40
• "Pass" if 40 ≤ score < 60
• "Good" if 60 ≤ score < 80
• "Excellent" if score ≥ 80
4. Print formatted summaries using string operations:
• Count of students per category
• Overall mean, minimum, and maximum scores
• Branch-wise student count and mean scores
5. Save data to CSV file with columns: Student_ID, Branch, Score, Category
6. Create three visualizations:
• Histogram of all exam scores
• Bar chart of performance categories
• Bar chart of branch-wise student distribution
Dept. of CS&E, MSRIT
Assignment Solution
[Link]
usp=sharing
Dept. of CS&E, MSRIT