0% found this document useful (0 votes)
7 views5 pages

Python Data Visualization Techniques

The document provides a comprehensive guide on data visualization using Python, specifically with libraries like Seaborn and Matplotlib. It includes examples of various plot types such as bar plots, line plots, scatter plots, heatmaps, histograms, and pie charts, demonstrating how to visualize data effectively. Additionally, it covers the use of built-in datasets and customization options for enhancing visual representation.

Uploaded by

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

Python Data Visualization Techniques

The document provides a comprehensive guide on data visualization using Python, specifically with libraries like Seaborn and Matplotlib. It includes examples of various plot types such as bar plots, line plots, scatter plots, heatmaps, histograms, and pie charts, demonstrating how to visualize data effectively. Additionally, it covers the use of built-in datasets and customization options for enhancing visual representation.

Uploaded by

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

Data Visualization using Python

Programming

Seaborn
import seaborn as sns

import [Link] as plt

import pandas as pd

data = sns.load_dataset("tips") # built-in dataset

# Bar Plot
[Link](x="day", y="total_bill", data=data)

[Link]("Average Total Bill by Day")

[Link]()

# Line Plot
[Link](x="size", y="tip", data=data)

[Link]("Tip vs Group Size")

[Link]()

# Scatterplot
[Link](figsize=(7, 5))

[Link](data=tips, x="total_bill", y="tip")

[Link]()

[Link](data=tips, x="total_bill", y="tip", color="red") #single


color (same for all points)

[Link](data=tips, x="total_bill", y="tip", hue="sex") #color by


category

[Link](data=tips, x="total_bill", y="tip", hue="sex",


style="smoker") #styles
print([Link]()) # First 5 rows

print([Link]()) # Last 5 rows

print([Link]) ['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']


#prints columns

print([Link]()) #Tells you which columns are numerical vs. categorical.

#Heatmap
import seaborn as sns

import [Link] as plt

data = [Link](0, 3, (15, 15)) // [Link] tells NumPy to


make random numbers that follow a normal distribution, 0 is the mean, 3
is the SD and 15, 15 is the grid with 15 rows and 15 columns

corr = [Link](numeric_only=True)

[Link](corr, annot=True, cmap='coolwarm’)

[Link](label='Value')

[Link]('Feature Correlation Heatmap’)

[Link]()

#[Link](...) → uses Seaborn to make a heatmap (like a colored


grid ).

•corr → this is the data we want to show (the correlation numbers).

•annot=True → writes the actual number inside each box (so you can see
+1.0, -0.8, etc.).

•cmap='coolwarm' → sets the color theme

#Histogram
import [Link] as plt

import seaborn as sns import numpy as np

# Generate random data (mean = 5, std = 2, 1000 values)

data = [Link](5, 2, 1000)


# Matplotlib Histogram (basic)
[Link](1, 2, 2)

[Link](data, bins=25, color='skyblue', edgecolor='black, kde=True')

[Link]('Matplotlib Histogram (basic)')

[Link]('Value')

[Link]('Frequency')

[Link](False) # turn off grid for contrast

plt.tight_layout()

[Link]()

#Seaborn Histogram
sns.set_theme(style="whitegrid")

[Link](1, 2, 1)

[Link](data, bins=25, color='skyblue', edgecolor='black', kde=True)


[Link]('Seaborn Histogram (with KDE)')

[Link]('Value')

[Link]('Frequency')

#Pairplot
import seaborn as sns

import [Link] as plt

df = sns.load_dataset('penguins')

[Link](df, hue='species')

[Link]()
Matplotlib
#Lineplot
import [Link] as plt

[Link](x, y)

[Link]('X-axis')

[Link]('Y-axis')

[Link]('Line Plot')

[Link](['Line'])

[Link]()

#Bar Chart
import [Link] as plt

categories = ['A', 'B', 'C', 'D']

values = [10, 15, 7, 12]

[Link](categories, values)

[Link]('Category')

[Link]('Value')

[Link]('Bar Chart')

[Link]()

#Scatterplot
import [Link] as plt

[Link](x, y)

[Link]('X-axis')

[Link]('Y-axis')

[Link]('Scatter Plot')

[Link]()
# Pie Chart
import [Link] as plt

import seaborn as sns

data = [44, 45, 40, 41, 39]

labels = ['Class 1', 'Class 2', 'Class 3', 'Class 4', 'Class 5']

colors = sns.color_palette('bright')

[Link](data, labels=labels, colors=colors, autopct='%.0f%%')

[Link]()

You might also like