0% found this document useful (0 votes)
6 views36 pages

Week02 DataVisualization

The document discusses the significance of data visualization and storytelling in data analysis, emphasizing the importance of clarity, accuracy, and relevance in visual representations. It outlines various visualization techniques suitable for different data types, such as categorical, numerical, and multivariate data, while also highlighting principles for effective visualization design. Additionally, it covers the elements of data storytelling, including the narrative, visual elements, and the importance of context and calls to action.

Uploaded by

wangyan233666
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views36 pages

Week02 DataVisualization

The document discusses the significance of data visualization and storytelling in data analysis, emphasizing the importance of clarity, accuracy, and relevance in visual representations. It outlines various visualization techniques suitable for different data types, such as categorical, numerical, and multivariate data, while also highlighting principles for effective visualization design. Additionally, it covers the elements of data storytelling, including the narrative, visual elements, and the importance of context and calls to action.

Uploaded by

wangyan233666
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Data Visualization &

Data Storytelling
Dr Yeo Wee Kiang

IS5126 Hands-on with Applied Analytics 1


IS5126 Hands-on with Applied Analytics

Overview
• Importance of Data Visualization • Data visualization with Matplotlib and
• Why visualizing data is crucial for data analysis Seaborn
• How data type influences the choice of visualization
• Basic line plots, scatter plots, histograms, box plots, and pair
• Selecting the appropriate visualization type plots

• Principles of effective data visualization • Work with multiple subplots to create complex visualizations

• Clarity, Accuracy, Relevance, Efficiency, Simplicity, and • Galleries of Matplotlib and Seaborn visualizations
Appropriateness
• Aesthetics and Storytelling

• Colour, typography and layout


• Using colour, typography, and layout effectively

• Data Storytelling: Elements and Techniques


• The importance of storytelling

• The different elements of data storytelling

Unauthorized distribution or sharing of these materials is strictly prohibited. 2


IS5126 Hands-on with Applied Analytics

Importance of Data Visualization


• Enhanced Comprehension and Complexity Simplification
• Data visualizations transform complex datasets into easily understandable formats.
• They simplify the complexity of large, intricate datasets, making it easier for individuals to grasp patterns,
trends, and insights within the data.
• Visualizations are often easier to remember than raw data, aiding in retaining and
recalling critical information.
• Facilitate Decision-Making and Effective Communication
• Visualizations empower decision-makers by providing clearer, more actionable
information.
• Visualizations serve as a universal language, bridging the gap between data experts
and non-experts.
• They facilitate communication by presenting data in a manner that is accessible to a broad
audience.

Unauthorized distribution or sharing of these materials is strictly prohibited. 3


IS5126 Hands-on with Applied Analytics

Importance of Data Visualization


• Identification of Anomalies
• Visualizations quickly reveal anomalies, outliers, and unexpected trends in the data.
• Analysts can spot errors, fraud, or areas requiring further investigation.
• Storytelling and Interactivity
• Data visualizations enable the storytelling of data.
• Analysts can convey narratives, share insights, and build compelling cases by connecting data points into
a coherent story.

• Data visualizations encourage exploration and discovery, promoting a more dynamic


approach to data analysis.
• Interactive visualizations enable users to delve into data, ask questions, and discover hidden insights.

Unauthorized distribution or sharing of these materials is strictly prohibited. 4


IS5126 Hands-on with Applied Analytics

How data type influences the choice of visualization

• Categorical Data
• Bar Plots/Charts: Categorical data, such as product categories or customer segments, are
often best represented using bar charts. Each category corresponds to a bar, and the height
of the bar represents the frequency or value associated with that category.
• Pie Charts: When you want to show the parts of a whole, like the market share of different
products, a pie chart can be effective.
• Numerical Data or Time-Series Data
• Line Plots/Charts: Numerical data, especially time-series data, is commonly visualized
using line charts. This allows you to track changes over a continuous range, such as stock
prices over time.
• Scatter Plots: When you need to explore relationships between two numerical variables,
scatter plots help identify correlations or patterns. For instance, you can use them to analyse
the relationship between a person's age and income.

Unauthorized distribution or sharing of these materials is strictly prohibited. 5


IS5126 Hands-on with Applied Analytics

How data type influences the choice of visualization

• Multivariate Data
• Heatmaps: For multivariate data, where relationships between multiple variables need to be
explored simultaneously, heatmaps are valuable. They use colour intensity to represent the
strength or magnitude of relationships between variables.
• Parallel Coordinates: In cases where there are many variables to compare, parallel
coordinates plots can be used to visualize multivariate data effectively.

• Text Data
• Word Clouds: When dealing with text data, such as word frequency in a document or
sentiment analysis results, word clouds provide a visually engaging way to highlight the
most frequently occurring words.

Unauthorized distribution or sharing of these materials is strictly prohibited. 6


IS5126 Hands-on with Applied Analytics

How data type influences the choice of visualization

• Hierarchical Data
• Tree Maps: When dealing with hierarchical data structures, like the organization of a
company, tree maps provide a compact and informative way to display nested categories
and their proportions within larger categories.

• Network Data
• Network Graphs: Data involving relationships between entities, like social networks or
computer networks, can be visualized using network graphs. Nodes represent entities, and
edges represent connections between them..

Unauthorized distribution or sharing of these materials is strictly prohibited. 7


IS5126 Hands-on with Applied Analytics

Selecting the appropriate visualization type

Distribution
• Definition: Probability of outcome occurrence.
• Represented with:
• Histograms
• Example: Histogram showing the distribution of
exam scores.
• Scatter plots
• Example: Scatter plot can be used to visualize
the distribution of property prices against their
square footage.
Dispersion
• Definition: Spread around central tendency.
• Represented with:
• Boxplots
• Example: In a dataset of employee salaries, a
boxplot can be used to visualize the dispersion
of salaries within the organization.
Image source: [Link]

Unauthorized distribution or sharing of these materials is strictly prohibited. 8


IS5126 Hands-on with Applied Analytics

Selecting the appropriate visualization type

Comparison
• Definition: Compare multiple variables or categories.
• Represented with:
• Bar charts
• Example: Bar chart comparing revenue between
different product categories.
• Line graphs
• Example: Line graph illustrating the growth trends
of multiple companies.
Relationship
• Definition: Connection between variables.
• Represented with:
• Scatter plots
• Example: Scatter plot showing the relationship
between temperature and ice cream sales.

Image source: [Link]

Unauthorized distribution or sharing of these materials is strictly prohibited. 9


IS5126 Hands-on with Applied Analytics

Selecting the appropriate visualization type

Composition
• Definition: Display variable composition in absolute
and normalized forms.
• Represented with:
• Stacked bar charts
• Example: Stacked bar chart displaying the
composition of a population by age groups.
• Pie charts
• Example: Pie chart showing the composition of a
budget, e.g., expenses.
• Tree maps
• Example: A tree map visualizes a company's
expense distribution by department, with each
rectangle symbolizing a department's budget
allocation.

Image source: [Link]

Unauthorized distribution or sharing of these materials is strictly prohibited. 10


IS5126 Hands-on with Applied Analytics

Selecting the appropriate visualization type


• Comparison of Multiple Variables (Multivariate Data)
• Heatmaps are effective for comparing relationships between multiple variables
simultaneously. They use colour intensity to represent the strength or magnitude of
relationships between variables.
• Parallel coordinates plots help compare multivariate data by displaying multiple variables on
parallel axes, making it easier to identify patterns and trends.

Unauthorized distribution or sharing of these materials is strictly prohibited. 11


IS5126 Hands-on with Applied Analytics

Principles of effective data visualization


Principles Examples Visualization

Clarity: Financial analyst presents quarterly revenue


• Easily understood by the figures.
audience. • Uses a clear and straightforward line chart.
• Choose the right chart type. • Each quarter's revenue is distinct and labeled.
• Ensures a visible revenue trend for stakeholders'
• Clear labels and scales.
understanding.
• Avoid unnecessary complexity.

Accuracy: Medical researcher analyzes clinical trial results.


• Emphasizes precise scales and measurements.
• Faithfully represent actual data
• Incorrect scaling or labeling can lead to
values.
misinterpretations.
• Use accurate scaling and labeling.
• Focus on maintaining accuracy for medical
• Avoid misleading visualizations. decisions.

Unauthorized distribution or sharing of these materials is strictly prohibited. 12


IS5126 Hands-on with Applied Analytics

Principles of effective data visualization


Principles Examples Visualization

Relevance: Digital marketing manager presents website traffic


• Every element contributes to data.
understanding. • Focuses on user traffic sources, demographics, and
• Omit irrelevant data or elements. conversion rates.
• Excludes irrelevant details like internal staff visits.
• Convey a clear and focused
• Aims to provide actionable insights to the marketing
message.
team.

Efficiency: Retail manager efficiently conveys monthly sales


• Quick and easy insights trends.
extraction. • Prioritizes clear, uncluttered visualization.
• Use visual cues for key points. • Selects a line chart for trend representation.
• Uses styles/markers for year-on-year comparison.
• Enhance decision-making.
• Annotates interesting point using red arrow.

Unauthorized distribution or sharing of these materials is strictly prohibited. 13


IS5126 Hands-on with Applied Analytics

Principles of effective data visualization


Principles Examples Visualization

Simplicity: Environmental scientist presents air quality data.


• Avoid unnecessary complexity. • Chooses a simple, easy-to-understand heat map.
• Keep visualizations • Depicts air pollution levels using colour intensity.
• Ensures that individuals without scientific
straightforward.
backgrounds can grasp air quality severity.
• Retain essential meaning.

Appropriateness: Sales manager analyzes sales performance.


• Consider the context. • Chooses a regional bar chart over a national-level
• Choose the right chart type and map.
• Allows for better comparison of sales figures within
details.
specific areas.
• Suit the visualization to its
• Aids in gaining a deeper understanding of regional
purpose and audience.
sales trends.

Unauthorized distribution or sharing of these materials is strictly prohibited. 14


IS5126 Hands-on with Applied Analytics

Principles of effective data visualization


Principles Examples Visualization

Aesthetics: Data journalist creates an pie chart for election


• Focus on visual appeal and results.
design. • Carefully selects a visually appealing color palette.
• Use harmonious color palettes • Aesthetics make the infographic engaging and
reader-friendly.
and fonts.
• Encourages readers to explore the data further.
• Enhance engagement and
attention.

Unauthorized distribution or sharing of these materials is strictly prohibited. 15


IS5126 Hands-on with Applied Analytics

Principles of effective data visualization


Principles Examples Visualization

Story-telling: Climate scientist presents climate change data.


• Convey a narrative using data. • Crafts a data-driven narrative starting with historical
• Structure information logically. trends.
• Introduces recent anomalies and forecasts future
• Guide the audience through a
scenarios.
story arc.
• Engages the audience in a compelling story
• Highlight key insights and trends.
emphasizing the urgency of addressing
• Aid in decision-making and environmental issues.
retention.

Fictional data
Unauthorized distribution or sharing of these materials is strictly prohibited. 16
IS5126 Hands-on with Applied Analytics

Colour, typography and layout


• Colour
Use colour sparingly and with purpose. Too many colours can lead to clutter and confusion.
• Colour can be used to represent different data categories or highlight specific data points. For example, in a bar chart
comparing sales by region, each region can be assigned a distinct colour for easy differentiation.
• Colour can also be used to encode quantitative information, such as heatmaps where colour intensity represents
values.
• Consider colourblind-friendliness by using colour combinations that are distinguishable for all viewers.

• Typography
Maintain consistency in font usage throughout the visualization. Use one or two fonts at most
to avoid visual clutter.
• Choose fonts that are easy to read, even when text size is small. Clarity should always be a priority.
• Use typography to provide context and explanations. Titles, labels, and captions should be informative and clear.
• Experiment with font size and weight to guide the viewer's attention. Larger, bold text can draw attention to key points
or insights
Unauthorized distribution or sharing of these materials is strictly prohibited. 17
IS5126 Hands-on with Applied Analytics

Colour, typography and layout


• Layout
A well-structured layout enhances comprehension and guides the viewer's attention.
• Layout refers to the arrangement of elements within a visualization.
• Organize content logically, placing the most critical information prominently.
• Leave adequate white space to reduce visual clutter and make the visualization more digestible.
• Consider the flow of information. Viewers should be able to follow a natural progression when interpreting the
visualization.

Unauthorized distribution or sharing of these materials is strictly prohibited. 18


IS5126 Hands-on with Applied Analytics

Data Storytelling: Elements and Techniques


• The data
• The data is the foundation of any data story. It is important to choose the right data that fits the story you want to tell.
Make sure the data is accurate, reliable, and relevant.

• The narrative
• Your narrative is the heart of the data story. It should be clear, concise, and engaging. Create a story that guides your
audience through the data's insights, making complex information easy to understand and relate to.

• Visual elements
• Visuals play an important role in data storytelling. They should complement your narrative, making complex data more
accessible. Use clear and visually appealing charts, graphs, and images to enhance the story's impact.

• Contextual information
• Providing context is essential to help your audience understand the significance of the data. Include definitions,
explanations, and historical context as needed. This background information ensures that your audience understands
the story's relevance.

• Call to action
• The call to action is what you want the audience to do after they have read your story. It could be to learn more, take
action, or simply think about the issue in a new way.
Unauthorized distribution or sharing of these materials is strictly prohibited. 19
IS5126 Hands-on with Applied Analytics

Hypothetical example: Creating an effective data story


Benefits of building more hospitals in Singapore
Suppose you are a Data Scientist working for a consulting firm. Imagine you have been tasked by the
Ministry of Health (MOH) to create a data story that will show the benefits of building more hospitals in
Singapore.
What do you want to achieve with your data story? Your question or goal could be:
• "How many more hospitals do we need to build in Singapore to meet the growing demand for healthcare?"
• "What are the economic benefits of building more hospitals in Singapore?"
• "How can building more hospitals improve the quality of healthcare in Singapore?"
Choose the right data.
• The data should be relevant to the story that you want to tell. It should also be accurate and reliable.
• In this case, you could use the following data:
• the number of hospital beds per 1,000 people in Singapore compared to the WHO recommended level,
• the average wait time for a hospital bed in Singapore,
• the number of people aged 65 and over in Singapore by 2030,
• the cost of healthcare in Singapore.

Unauthorized distribution or sharing of these materials is strictly prohibited. 20


IS5126 Hands-on with Applied Analytics

Hypothetical example: Creating an effective data story


Benefits of building more hospitals in Singapore
Tell a clear and concise story.
• The narrative should be easy to understand and follow. It should also be engaging and
interesting.
• Your story could start by explaining the growing demand for healthcare in Singapore.
• You could then provide data on the number of hospital beds per 1,000 people in Singapore,
average wait time for a hospital bed, and the cost of healthcare in Singapore.
• You could also talk about the impact of the lack of hospital beds on patients, such as longer
waiting times and the risk of health complications.

Unauthorized distribution or sharing of these materials is strictly prohibited. 21


IS5126 Hands-on with Applied Analytics

Hypothetical example: Creating an effective data story


Benefits of building more hospitals in Singapore
Use visuals to help tell the story.
• Visuals can help to make the story more clear, concise, and visually appealing.
• You could use data visualizations (charts, graphs, and infographics) to illustrate your data.
They could illustrate the following:
• The number of hospital beds in Singapore over time.
• The number of hospital beds per capita in Singapore compared to other countries.
• The factors that have contributed to the shortage of hospital beds in Singapore.
• The impact of the shortage of hospital beds on patients, healthcare providers, and the healthcare
system.
• You could also use images and videos to tell the stories of real people who have been
affected by the lack of hospital beds.

Unauthorized distribution or sharing of these materials is strictly prohibited. 22


IS5126 Hands-on with Applied Analytics

Hypothetical example: Creating an effective data story


Benefits of building more hospitals in Singapore
Provide context.
• The audience needs to understand the context of the story to understand it.
• Provide definitions: When using terms that may not be familiar to your audience, provide clear
and concise definitions. This will help them understand the data and its implications.
• For example, if you are presenting about the average wait time for a doctor's appointment in Singapore, you could define
"average wait time" as "the amount of time it takes for a patient to see a doctor after making an appointment."

• Provide explanations: This could include providing background information, explaining the
methodology used to collect the data, or interpreting the results of the data.
• For example, if you are presenting about the quality of healthcare in Singapore, you could explain the different factors
that are used to measure quality, such as patient satisfaction, clinical outcomes, and patient safety.

• Provide historical context: This could include explaining the events that led to the data, or the
changes that have occurred over time.
• For example, you could provide historical context for the number of hospital beds in Singapore by explaining how it has
changed over time, such as due to changes in the population, the healthcare system, or the economy.

Unauthorized distribution or sharing of these materials is strictly prohibited. 23


IS5126 Hands-on with Applied Analytics

Hypothetical example: Creating an effective data story


Benefits of building more hospitals in Singapore
Include a call to action [CTA].
• What do you want the audience to do after they have listened to your story?
• You could end your story with a call to action, such as:

"The shortage of hospital beds is a growing problem, and we need to act now to address it.
We can all play a role in making sure that everyone has access to quality healthcare.

Here are some things you can do:


• Support the MOH's plan to build more hospitals in Singapore.
• Educate yourself and others about the importance of healthcare.
• Volunteer your time at a local hospital.

We all want our loved ones to have access to quality healthcare."

Unauthorized distribution or sharing of these materials is strictly prohibited. 24


IS5126 Hands-on with Applied Analytics

Reality: Upcoming Healthcare Facilities in Singapore

[Link]

Unauthorized distribution or sharing of these materials is strictly prohibited. 25


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Basic line plot
import pandas as pd import seaborn as sns
import [Link] as plt import pandas as pd
import [Link] as plt
# Sample data
data = {'x': [1, 2, 3, 4, 5], 'y': [10, 12, 5, 8, 9]} # Sample data
df = [Link](data) data = {'x': [1, 2, 3, 4, 5], 'y': [10, 12, 5, 8, 9]}
df = [Link](data)
# Create a basic line plot with Matplotlib
[Link](df['x'], df['y']) # Create a basic line plot with Seaborn
[Link](data=df, x='x', y='y')
# Add labels and a title
[Link]('X-axis') # Add labels and a title
[Link]('Y-axis') [Link]('X-axis')
[Link]('Basic Line Plot with Matplotlib') [Link]('Y-axis')
[Link]('Basic Line Plot with Seaborn')
# Show the plot
[Link]() # Show the plot
[Link]()

Unauthorized distribution or sharing of these materials is strictly prohibited. 26


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Bar chart
import pandas as pd
import [Link] as plt

# Sample data for a bar chart


data = {'Category': ['A', 'B', 'C', 'D'], 'Values': [25, 40, 30, 50]}
df = [Link](data)

# Create a bar chart


[Link](df['Category'], df['Values'])

# Add labels and a title


[Link]('Categories')
[Link]('Values')
[Link]('Bar Chart with Matplotlib')

# Show the plot


[Link]()

Unauthorized distribution or sharing of these materials is strictly prohibited. 27


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Bar chart
import seaborn as sns
import pandas as pd
import [Link] as plt

# Sample data for a bar chart


data = {'Category': ['A', 'B', 'C', 'D'], 'Values': [25, 40, 30, 50]}
df = [Link](data)

# Create a bar chart with Seaborn


[Link](data=df, x='Category', y='Values')

# Add labels and a title


[Link]('Categories')
[Link]('Values')
[Link]('Bar Chart with Seaborn')

# Show the plot


[Link]()

Unauthorized distribution or sharing of these materials is strictly prohibited. 28


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Histogram
import pandas as pd
import [Link] as plt

# Sample data
data = [15, 20, 22, 25, 30, 32, 35, 38, 40, 42, 45, 50, 52, 55]

# Create a Pandas DataFrame


df = [Link](data, columns=['Values'])

# Create a histogram with Matplotlib


[Link](df['Values'], bins=5, color='orange', edgecolor='black')

[Link]('Values')
[Link]('Frequency')
[Link]('Histogram with Matplotlib')
[Link]()

import pandas as pd
import seaborn as sns
import [Link] as plt

# Sample data
data = [15, 20, 22, 25, 30, 32, 35, 38, 40, 42, 45, 50, 52, 55]

# Create a Pandas DataFrame


df = [Link](data, columns=['Values'])

# Create a histogram with Seaborn


[Link](data=df, x='Values', bins=5, color='orange', edgecolor='black')

[Link]('Values')
[Link]('Frequency')
[Link]('Histogram with Seaborn')
[Link]()

Unauthorized distribution or sharing of these materials is strictly prohibited. 29


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Box Plot
import pandas as pd
import [Link] as plt

# Sample data
data = {
'Group A': [25, 30, 35, 40, 45, 50, 55, 60, 65, 70],
'Group B': [20, 22, 25, 30, 35, 40, 42, 45, 50, 55]
}

# Create a Pandas DataFrame


df = [Link](data)

# Create two box plots side by side


[Link]([df['Group A'], df['Group B']], labels=['Group A', 'Group B'])
[Link]('Groups')
[Link]('Values')
[Link]('Box Plots with Matplotlib')
[Link]()

import pandas as pd
import seaborn as sns
import [Link] as plt

# Sample data
data = {
'Group A': [25, 30, 35, 40, 45, 50, 55, 60, 65, 70],
'Group B': [20, 22, 25, 30, 35, 40, 42, 45, 50, 55]
}

# Create a Pandas DataFrame


df = [Link](data)

# Create two box plots side by side with Seaborn


[Link](data=df)
[Link]('Groups')
[Link]('Values')
[Link]('Box Plots with Seaborn') 30
[Link]() Unauthorized distribution or sharing of these materials is strictly prohibited.
IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Scatter plot
import pandas as pd
import [Link] as plt

# Sample data for a scatter plot


data = {'X': [1, 2, 3, 4, 5], 'Y': [10, 12, 5, 8, 9], 'Group': ['A', 'B', 'A', 'B', 'A']}
df = [Link](data)

# Define colours and markers for each group


colours = {'A': 'red', 'B': 'blue'}
markers = {'A': 'o', 'B': 's'}

# Create a scatter plot


for group, group_data in [Link]('Group'):
[Link](group_data['X'], group_data['Y'], label=group, color=colours[group], marker=markers[group])

# Add labels, a title, and a legend


[Link]('X-axis')
[Link]('Y-axis')
[Link]('Scatter Plot with Matplotlib')
[Link](title='Group')

# Show the plot


[Link]()

Unauthorized distribution or sharing of these materials is strictly prohibited. 31


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Scatter plot
import seaborn as sns
import pandas as pd
import [Link] as plt

# Sample data for a scatter plot


data = {'X': [1, 2, 3, 4, 5], 'Y': [10, 12, 5, 8, 9], 'Group': ['A', 'B', 'A', 'B', 'A']}
df = [Link](data)

# Create a scatter plot


[Link](data=df, x='X', y='Y', hue='Group', palette='Set1', style='Group', markers=['o', 's'])

# Add labels, a title, and a legend


[Link]('X-axis')
[Link]('Y-axis')
[Link]('Scatter Plot with Seaborn')
[Link](title='Group')

# Show the plot


[Link]()

Unauthorized distribution or sharing of these materials is strictly prohibited. 32


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Scatter plot with annotation
import seaborn as sns
import pandas as pd
import [Link] as plt

# Sample data for a scatter plot


data = {'X': [1, 2, 3, 4, 5], 'Y': [10, 12, 5, 8, 9], 'Group': ['A', 'B', 'A', 'B', 'A']}
df = [Link](data)

# Create a scatter plot with Seaborn


[Link](data=df, x='X', y='Y', hue='Group', palette='Set1', style='Group', markers=['o', 's'])

# Add labels, a title, and a legend


[Link]('X-axis')
[Link]('Y-axis')
[Link]('Scatter Plot with Titles, Legend, and Annotations')
[Link](title='Group')

# Add an annotation
[Link]('Highlight', xy=(2, 12), xytext=(3, 11),
arrowprops=dict(arrowstyle='->', lw=1.5, color='black'),
bbox=dict(boxstyle='round,pad=0.5', edgecolor='black', facecolor='white'))

# Show the plot


[Link]()

Unauthorized distribution or sharing of these materials is strictly prohibited. 33


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Pair Plot
import pandas as pd
import seaborn as sns
import [Link] as plt

# Sample data
data = {'Feature1': [4, 1, 4, 1, 3, 8, 4, 5],
'Feature2': [7, 1, 10, 1, 7, 1, 10, 10],
'Feature3': [7, 3, 5, 5, 3, 1, 3, 3],
'Feature4': [8, 2, 6, 5, 3, 2, 4, 4],
'Feature5': [3, 10, 8, 6, 7, 9, 3, 7],
'Feature6': [1, 4, 7, 9, 2, 2, 1, 3],
'Feature7': [8, 10, 6, 3, 9, 4, 5, 4]}

# Create a Pandas DataFrame


df = [Link](data)

# Create a pair plot with Seaborn


[Link](df)
[Link]('Pair Plot with Seaborn', y=1.04)
[Link]()

Unauthorized distribution or sharing of these materials is strictly prohibited. 34


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Work with multiple subplots to create complex visualizations
import seaborn as sns # Customize individual subplots
import [Link] as plt axes[0, 0].set_xlabel('X-axis')
import numpy as np axes[0, 0].set_ylabel('Y-axis')

# Sample data for demonstration axes[0, 1].set_xlabel('X-axis')


x1 = [Link](0, 10, 100) axes[0, 1].set_ylabel('Y-axis')
y1 = [Link](x1)
axes[1, 0].set_xlabel('Categories')
x2 = [Link](50) axes[1, 0].set_ylabel('Values')
y2 = [Link](50)
axes[1, 1].set_xlabel('Bins')
x3 = ['Category A', 'Category B', 'Category C'] axes[1, 1].set_ylabel('Frequency')
y3 = [15, 20, 10]
# Add a legend to the scatter plot
data = [Link](1000) axes[0, 1].legend(['Data'], loc='upper right')

# Create a 2x2 grid of subplots # Adjust layout


fig, axes = [Link](2, 2, figsize=(10, 8)) plt.tight_layout()

# Plot in the first subplot (top-left) # Show the subplots


[Link](x=x1, y=y1, ax=axes[0, 0]) [Link]()
axes[0, 0].set_title('Line Plot')

# Plot in the second subplot (top-right)


[Link](x=x2, y=y2, ax=axes[0, 1])
axes[0, 1].set_title('Scatter Plot')

# Plot in the third subplot (bottom-left)


[Link](x=x3, y=y3, ax=axes[1, 0])
axes[1, 0].set_title('Bar Plot')

# Plot in the fourth subplot (bottom-right)


[Link](data, bins=20, ax=axes[1, 1])
axes[1, 1].set_title('Histogram')

Unauthorized distribution or sharing of these materials is strictly prohibited. 35


IS5126 Hands-on with Applied Analytics

Data visualization with Matplotlib and Seaborn


Galleries of Matplotlib and Seaborn visualizations

• [Link]
• [Link]

Unauthorized distribution or sharing of these materials is strictly prohibited. 36

You might also like