Artificial Intelligent
Instructor: Waqas Ahmed (Khilji Khan)
PhD (Scholar)…
[Link]
[Link]
1
Data Visualization Syllabus
Course Title: Data Visualization
Course Code: DV101
➢ Course Description:
This course introduces the principles and practices of data visualization, focusing on the design
and evaluation of effective visual representations of data. It covers a range of visualization
techniques, tools, and technologies to help students create meaningful visualizations that can
enhance data interpretation and decision-making processes.
➢ Course Objectives:
By the end of this course, students will be able to:
1. Understand the fundamentals of data visualization and its importance.
2. Design and implement various types of data visualizations.
3. Use data visualization tools and software effectively.
4. Evaluate the effectiveness of different visualization methods.
➢ Course Outline:
Week 1: Introduction to Data Visualization
• Definition and Importance
• History and Evolution of Data Visualization
• Types of Data Visualization
Week 2: Data Visualization Tools and Software
• Introduction to Tools: Matplotlib, Seaborn, Plotly, MS-Excel, Tableau, Power BI, [Link],
• Installation and Basic Operations
Week 3: Data Types and Data Preparation
• Understanding Different Data Types (Categorical, Numerical)
• Data Cleaning and Preprocessing Techniques Week 4: Principles of Visual
Design
• Gestalt Principles
• Color Theory
• Typography in Visualizations
Week 5: Creating Basic Charts
• Bar Charts, Line Charts, Pie Charts
2
• Best Practices and Common Pitfalls
Week 6: Advanced Visualizations
• Scatter Plots, Histograms, Box Plots
• Heatmaps, Bubble Charts
Week 7: Interactive Visualizations
• Dashboards and Storytelling with Data
• User Interaction Techniques
Week 8: Data Mapping and Geospatial Visualization
• Introduction to GIS
• Creating Maps with Data Overlays
Week 9: Data Visualization Ethics
• Misleading Visualizations
• Ethical Considerations in Data Representation
Week 10: Case Studies and Real-World Applications
• Industry Case Studies
• Project Planning and Execution
Week 11: Final Project Work
• Project Development
• Peer Reviews and Feedback
Week 12: Final Project Presentations
• Presentation of Final Projects
• Course Summary and Wrap-Up Recommended Textbooks:
• The Visual Display of Quantitative Information by Edward Tufte
• Storytelling with Data by Cole Nussbaumer Knaflic
• Information Dashboard Design by Stephen Few
Additional Resources:
• Online Tutorials and Documentation for Tableau, Power BI, and [Link] • Data Sets for Practice
from Kaggle
3
Introduction to Data Visualization
1. Definition and Importance
• Definition:
o Data Visualization is the graphical representation of information and data. By using
visual elements like charts, graphs, and maps, data visualization tools provide an
accessible way to see and understand trends, outliers, and patterns in data.
• Importance:
o Simplifies Complex Data: Makes complex data easier to understand. o Enhances
Comprehension: Improves the ability to grasp large amounts of data quickly. o Reveals
Trends and Patterns: Helps identify trends, patterns, and correlations. o Supports
Decision-Making: Facilitates more informed decision-making.
o Increases Accessibility: Makes data more accessible to non-experts.
2. History and Evolution of Data Visualization
• Early Beginnings: o Ancient Times: Use of maps and simple charts for navigation and
tracking.
o 17th Century: Introduction of the Cartesian coordinate system by René Descartes.
• 18th and 19th Century: o William Playfair: Creator of the line chart, bar chart, and pie chart.
o Florence Nightingale: Used pie charts to represent data on sanitation conditions in army
hospitals.
• 20th Century:
o Development of Modern Statistical Graphs: Histograms, scatter plots, and more
complex chart types.
o Introduction of Computers: Automation of data visualization through software.
• 21st Century:
o Big Data and Advanced Tools: Rise of big data and the development of sophisticated
tools like Tableau, Power BI, and [Link].
o Interactive Visualizations: Introduction of interactive dashboards and real-time data
visualizations.
3. Types of Data Visualization • Basic Visualization/ Charts:
o Bar Chart: Comparison of different categories. o
o Line Chart: Visualization of trends over time.
o Pie Chart: Proportional representation of parts to a whole.
• Advanced Visualizations:
o Scatter Plot: Relationship between two variables. o
o Histogram: Distribution of a single variable. o
o Heatmap: Intensity of data in a matrix form.
• Specialized Visualizations:
o Tree Maps: Hierarchical data as nested rectangles.
o Gantt Charts: Project timelines.
o Geospatial Maps: Data overlaid on geographic maps.
• Interactive Visualizations:
o Dashboards: Real-time data representation with multiple visual elements.
4
o Storytelling with Data: Interactive narratives built using visualizations.
OR
1. Charts (Comparisons & Trends)
• Bar Chart – Compare quantities across categories
• Column Chart – Similar to bar chart but vertical
• Line Chart – Show trends over time
• Area Chart – Highlight magnitude over time
• Stacked Bar/Column Chart – Show part-to-whole relationships
2. Distribution Visualizations
• Histogram – Show frequency distribution
• Box Plot (Whisker Plot) – Show spread, median, and outliers
• Violin Plot – Show distribution shape and density
• Dot Plot – Compare frequency/count
3. Relationship & Correlation
• Scatter Plot – Show relationship between two variables
• Bubble Chart – Like scatter plot but with size as third variable
• Heatmap – Show correlation using color intensity
4. Part-to-Whole Relationships
• Pie Chart – Show proportions of a whole
• Donut Chart – Like pie chart with a center cutout
• Treemap – Nested rectangles to show hierarchy and size
• Sunburst Chart – Hierarchical, radial representation
5. Ranking & Order
• Pareto Chart – Bar + line to show cumulative impact
• Lollipop Chart – Alternative to bar chart with dots
• Slope Chart – Compare change between two points
5
6. Geospatial Visualizations
• Choropleth Map – Map with color-coded regions
• Symbol Map – Locations marked with shapes or symbols
• Heatmap Map – Intensity representation on a map
• Flow Map – Show movement between locations
7. Time-Based Visualizations
• Timeline – Sequence of events
• Gantt Chart – Project schedule visualization
• Streamgraph – Flow of data over time
8. Advanced / Multidimensional
• Radar (Spider) Chart – Compare multiple variables
• Parallel Coordinates Plot – Visualize high-dimensional data
• Sankey Diagram – Show flow and proportion between categories
• Network Graph – Show connections and relationships
6
Week 2: Data Visualization Tools and Software
1. Introduction to Tools
• Matplotlib: o A popular Python library for creating static, interactive,
and animated visualizations. o Basic types of plots: line, bar, scatter,
histogram.
• Seaborn: o A Python data visualization library based on Matplotlib.
o Provides a high-level interface for drawing attractive and informative statistical graphics.
o Enhances Matplotlib with more complex visualizations such as violin plots, box
plots, and heatmaps.
• Plotly: o An open-source graphing library for Python that supports
interactive visualizations. o Can create complex and highly interactive
plots, including 3D plots.
• MS-Excel: o A widely used tool for data manipulation and visualization.
o Built-in chart types such as bar, pie, line charts, and pivot tables for summarizing data.
7
• Tableau: o A powerful data visualization tool used in the business
intelligence industry. o Allows users to create interactive and shareable
dashboards.
• Power BI:
o A Microsoft product for business analytics that provides interactive visualizations with
self-service business intelligence capabilities.
o Easy integration with
a wide range of data
sources.
8
• [Link]:
o A JavaScript library for producing dynamic, interactive data visualizations in web
browsers.
o It uses HTML, SVG, and CSS to render charts and diagrams.
Week 3: Data Types and Data Preparation
• Understanding Different Data Types (Categorical, Numerical)
• Data Cleaning and Preprocessing Techniques
Understanding Different Data Types 1. Categorical Data
Categorical data represents characteristics or attributes that can be divided into distinct categories
or groups. These data types are qualitative in nature and are typically used to label or name
items.
• Types of Categorical Data:
o Nominal:
▪ Data that can be categorized without a specific order.
▪ Example: Gender (Male, Female), Colors (Red, Blue, Green).
o Ordinal:
▪ Data that can be categorized and ordered.
▪ Example: Satisfaction Level (Satisfied, Neutral, Dissatisfied), Educational Level
(High School, Bachelor's, Master's).
• Characteristics:
o Cannot perform arithmetic operations on categorical data.
o Often visualized using bar charts or pie charts.
2. Numerical Data
Numerical data represents quantities and is quantitative in nature. These data types are expressed
in numbers and allow for arithmetic operations.
• Types of Numerical Data:
o Discrete:
▪ Data that takes specific values and cannot be subdivided.
▪ Example: Number of students in a class, Number of cars in a parking lot.
o Continuous:
▪ Data that can take any value within a range and can be subdivided into finer
levels.
▪ Example: Height, Weight, Temperature.
• Characteristics:
o Can perform arithmetic operations like addition, subtraction, multiplication, and division.
o Often visualized using histograms, line charts, or scatter plots.
9
Week 5: Creating Basic Charts
• Bar Charts, Line Charts, Pie Charts
• Best Practices and Common Pitfalls
1. Bar Charts
• Definition: A bar chart is a graphical display of data using bars of different heights or
lengths to compare values across categories.
• Uses: Ideal for comparing different groups or tracking changes over time.
• Creating a Bar Chart: o X-axis represents categories. o Y-axis represents values.
o Bars can be vertical or horizontal.
• Common Tools: Matplotlib, Seaborn, Excel, Tableau.
2. Line Charts
• Definition: A line chart connects individual data points using a line to show trends over
time or continuous data.
• Uses: Useful for showing trends, patterns, and fluctuations over time.
• Creating a Line Chart:
o X-axis represents time or continuous data.
o Y-axis represents values.
o Points are plotted and connected by lines.
• Common Tools: Matplotlib, Plotly, Excel, Power BI.
10
3. Pie Charts
• Definition: A pie chart displays data in a circular graph, with slices representing parts of
a whole.
• Uses: Best for showing proportional or percentage data.
• Creating a Pie Chart: o Each slice size corresponds to its proportion of the total.
o Useful when there are fewer categories.
• Common Tools: Matplotlib, Excel, Tableau.
4. Scatter Plots
• Definition: A scatter plot displays points plotted on two axes, showing the relationship
between two variables.
• Uses: Useful for identifying correlations, patterns, and outliers in data.
• Creating a Scatter Plot:
o X-axis and Y-axis represent two continuous variables.
o Points are plotted based on their values for these variables.
• Common Tools: Matplotlib, Seaborn, Plotly, Excel.
11
The Scatter Plot example. It shows the relationship between two variables, with each point
representing a data pair.
5. Histograms
• Definition: A histogram shows the distribution of a continuous variable by dividing the
range into intervals and displaying the count of data points in each interval.
• Uses: Best for showing frequency distributions and identifying skewness or modality.
• Creating a Histogram: o X-axis represents intervals (bins).
o Y-axis represents the frequency of data within each bin.
• Common Tools: Matplotlib, Seaborn, Excel.
12
The Histogram example, which illustrates the frequency distribution of the generated data. The x-axis
represents data intervals (bins), and the y-axis shows the count of data points in each bin.
6. Box Plots
• Definition: A box plot summarizes the distribution of a dataset and displays its five
number summary: minimum, first quartile, median, third quartile, and maximum.
• Uses: Effective for identifying outliers and understanding the spread and skewness of
data.
• Creating a Box Plot:
o Box represents the interquartile range (IQR). o Line inside the box shows the median.
o Whiskers extend to the minimum and maximum values within 1.5 * IQR.
• Common Tools: Seaborn, Matplotlib, Excel.
13
This is the Box Plot example, which shows the distribution of three datasets, highlighting their medians,
quartiles, and potential outliers.
7. Heatmaps
• Definition: A heatmap is a data visualization that uses color to represent the magnitude of
values in a matrix format.
• A heat map is a graphical representation of data where the individual values contained in
a matrix are represented as colors. 1 Each color represents a specific range of values.
• Uses: Ideal for visualizing correlation matrices, frequency tables, and complex datasets.
• Creating a Heatmap: o Rows and columns represent different categories or variables.
o Colors indicate the intensity or value of data points.
• Common Tools: Seaborn, Matplotlib, [Link].
14
8. Bubble Charts
• Definition: A bubble chart is an extension of the scatter plot where each point is
represented by a bubble, and the size of the bubble indicates an additional dimension of
data.
• Uses: Effective for showing relationships between three variables.
• Creating a Bubble Chart: o X-axis and Y-axis represent two variables.
o The size of the bubble represents a third variable.
• Common Tools: Plotly, [Link], Excel.
15
Best Practices and Common Pitfalls
Best Practices:
• For Bar Charts: o Use consistent colors for categories. o Label axes clearly.
o Keep bar width proportional to the space between bars.
• For Line Charts: o Use appropriate scales to avoid distortion. o Label key points or events on
the chart.
o Use different line styles or colors for multiple data series.
• For Pie Charts: o Limit the number of slices to avoid clutter. o Use contrasting colors for
different slices.
o Display percentage or value labels for clarity.
Common Pitfalls:
• For Bar Charts: o Avoid 3D effects, which can distort perception.
o Be cautious of overlapping bars when displaying multiple categories.
• For Line Charts: o Avoid using too many lines, which can make the chart hard to read.
o Ensure data intervals on the X-axis are consistent.
• For Pie Charts: o Avoid using pie charts for data sets with too many categories.
o Do not use when differences between slices are minimal, as it can be misleading.
Introduction to Matplotlib
What is Matplotlib?
16
Matplotlib is a comprehensive plotting library for creating static, animated, and interactive
visualizations in Python. It provides a variety of tools for generating a wide range of
visualizations, from basic line plots to complex 3D graphs. It is highly customizable and is
widely used in scientific computing, data analysis, and machine learning for visualizing data.
Basic Features and Functionality
• Plot Types: Matplotlib supports a variety of plot types, such as line plots, bar charts, histograms,
scatter plots, pie charts, heatmaps, 3D plots, and more.
• Customization: It allows fine-grained control over every aspect of the plot, including axes, labels,
titles, legends, colors, and styles.
• Integration: Matplotlib can be easily integrated with other Python libraries like NumPy, Pandas,
and SciPy, enabling seamless data manipulation and visualization.
• Subplots: Matplotlib can handle multiple plots on a single figure using the subplots()
function, making it easy to compare different datasets.
• Interactivity: Although Matplotlib is primarily known for static plots, it supports basic
interactivity, such as zooming and panning, when used in interactive environments like Jupyter
Notebooks.
• Saving Plots: You can save your plots in various formats like PNG, PDF, SVG, and more, making it
convenient for publishing and sharing.
Differences Between Matplotlib and Other Plotting Libraries
1. Matplotlib vs. Seaborn:
o Matplotlib is the foundation of most Python plotting libraries, including Seaborn. It
provides a lower-level API, giving full control over the plot's appearance but requiring
more code for customization.
o Seaborn is built on top of Matplotlib and is designed to make it easier to create
aesthetically pleasing and informative plots with minimal code. Seaborn integrates well
with Pandas DataFrames and automatically handles some aspects of styling and color
palettes.
o Key Differences: Matplotlib is more versatile and customizable, whereas Seaborn
focuses on simplicity and ease of use for creating statistical visualizations with less code.
2. Matplotlib vs. Plotly:
o Plotly is a more modern and powerful visualization library that is highly interactive and
can create web-based interactive plots out of the box.
o Matplotlib is focused primarily on static visualizations, though interactivity can be added
through additional libraries (e.g., mpl_toolkits.mplot3d).
o Key Differences: Plotly excels in creating interactive and dynamic plots for web
applications, while Matplotlib is best suited for static, publication-quality plots. Plotly
has better support for web-based deployments and animations, while Matplotlib is a
goto choice for more customizable static plots.
Setting Up the Environment
17
Matplotlib can be used in various environments like Jupyter Notebooks, Python IDEs (e.g.,
PyCharm, VSCode), or directly through the Python interpreter. Below are instructions for setting
up the environment for each:
1. Setting Up in Jupyter Notebook
Jupyter Notebook provides an interactive environment for running Python code and visualizing
plots inline.
➢ Install Jupyter Notebook (if not installed): You can install Jupyter Notebook using the
following command:
pip install notebook
➢ Launching Jupyter Notebook: After installation, you can start Jupyter Notebook by running the
following command in your terminal or command prompt:
jupyter notebook
Use Matplotlib in Jupyter: In a Jupyter Notebook cell, you can use Matplotlib as follows:
2. Setting Up in Python IDE (PyCharm, VSCode, etc.)
• PyCharm:
1. Install PyCharm if you don't have it: PyCharm Download
2. Create a new Python project or open an existing one.
3. Open the terminal inside PyCharm and install Matplotlib using pip:
pip install matplotlib
After installation, you can write Python code in the editor and use Matplotlib to generate plots. PyCharm
will automatically display the plots in a separate window or interactive plot window, depending on the
settings.
18
VSCode:
1. Install Visual Studio Code if you don't have it: VSCode Download 2.
Install the Python extension for VSCode.
3. Open the terminal in VSCode and install Matplotlib using pip:
pip install matplotlib
Write your Python code in a .py file and use Matplotlib for plotting. To see the plots, you might need to
call [Link]() in your script to display the plots in a new window.
19