12-data visualization-1
12-data visualization-1
Analytics-MGT173
Rabail Asghar
Lecturer (Computer Science)
COMSATS University Islamabad, Lahore Campus
1
Topics to cover
2
Data Visualization
• What is Data Visualization?
• Data visualization is the graphical representation of
information and data. It uses visual elements like
charts, graphs, and plots to make complex data
easy to understand and analyze.
3
Data Visualization
• Why is Data Visualization Important in Business?
1.Simplifies Complex Data: Makes large datasets
easy to interpret.
2.Identifies Trends: Helps spot patterns and trends
over time.
3.Supports Decision-Making: Provides actionable
insights for better business decisions.
4.Improves Communication: Visuals are easier to
share and explain than raw data.
4
matplotlib
• Matplotlib is a Python library used to create graphs
and charts for data visualization. It helps us to
better understand and present data.
5
6
7
Explanation
• matplotlib.pyplot as plt:
• This creates a shorter alias (plt) for the module, so we
can use it more easily in the code. Instead of typing
matplotlib.pyplot every time, we can just write plt.
• The plt.plot() function creates a line graph connecting
the points defined by months and sales. It automatically
chooses colors, line styles, and markers unless you
specify them.
• E.g
plt.plot(months, sales, color='red', linestyle='--',
marker='o')
8
9
Types of Plots in
Matplotlib
• 1. Line Plot
• Used to display trends over intervals.
• Tracks a variable over intervals (like days, months,
years).
10
11
Line plot
• Manually setting the y-axis distribution
12
13
2. Bar Chart
• Used for comparing different categories.
• Shows the difference in quantities across
categories.
14
15
2. Bar Chart
• # Set the y-axis ticks manually
• plt.yticks([0, 300, 600, 900, 1000, 1300])
16
Pie-chart
Purpose: Used to show proportions of a whole.
• Code:
17
18
Explanation
• autopct='%1.1f%%’:
• This parameter formats the percentage values. The
%1.1f%% format string means:
• %1.1f: Display a floating-point number with one decimal
place.
• %%: To display the percentage sign (%).
19
Histogram
• Displays the distribution of data.
20
Histogram
21
22
Scatterplot
• A scatterplot is useful for visualizing the
relationship between two continuous variables.
• It shows how much one variable is affected by
another, which can help identify correlations
(positive, negative, or no correlation). Typically, the
x-axis and y-axis represent different continuous
variables.
23
24
25
Practice-1
• Read monthly_sales data from CSV file and plot
graphs between months and sales.
26