0% found this document useful (0 votes)
8 views4 pages

Day-5 DS Practical

Data visualization is the graphical representation of data to identify patterns and trends, aiding in data interpretation and decision-making. Key Python libraries for data visualization include Matplotlib for basic plotting, Seaborn for statistical visualizations, and Plotly for interactive graphics. The document provides examples of various plots, including line plots, bar charts, histograms, and more advanced visualizations like box plots and heatmaps.

Uploaded by

jothimala1507
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)
8 views4 pages

Day-5 DS Practical

Data visualization is the graphical representation of data to identify patterns and trends, aiding in data interpretation and decision-making. Key Python libraries for data visualization include Matplotlib for basic plotting, Seaborn for statistical visualizations, and Plotly for interactive graphics. The document provides examples of various plots, including line plots, bar charts, histograms, and more advanced visualizations like box plots and heatmaps.

Uploaded by

jothimala1507
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
You are on page 1/ 4

Introduction to Data Visualization

What is Data Visualization?

●​ The process of representing data graphically to uncover patterns,


trends, and relationships.
●​ Helps in understanding complex data and making data-driven
decisions.

Why Use Data Visualization?

●​ Makes data easier to interpret.


●​ Identifies trends and anomalies.
●​ Helps in storytelling with data.
●​ Useful for exploratory data analysis (EDA).

Python Libraries for Data Visualization:

●​ Matplotlib: Basic 2D plotting library.


●​ Seaborn: Statistical data visualization built on top of Matplotlib.
●​ Plotly: Interactive and web-based visualizations.

1. Matplotlib

1.1 Basic Matplotlib Plot


Line Plot

import matplotlib.pyplot as plt


import numpy as np

x = np.linspace(0, 10, 100)


y = np.sin(x)
plt.plot(x, y, label="Sine Wave")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("Simple Line Plot")
plt.legend()
plt.show()

1.2 Bar Chart


categories = ['A', 'B', 'C', 'D']
values = [10, 25, 15, 30]

plt.figure(figsize=(6, 4))
plt.bar(categories, values, color='purple')
plt.xlabel("Categories")
plt.ylabel("Values")
plt.title("Bar Chart Example")
plt.show()

1.3 Histogram (Distribution of Data)


data = np.random.randn(1000)

plt.figure(figsize=(7, 5))
plt.hist(data, bins=30, color='green', edgecolor='black', alpha=0.7)
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.title("Histogram Example")
plt.show()

2. Seaborn - Statistical Data Visualization


2.1 Histogram & KDE Plot
import seaborn as sns
import pandas as pd

# Creating sample data


data = np.random.randn(1000)
df = pd.DataFrame(data, columns=['Values'])

# Plot
sns.histplot(df['Values'], bins=30, kde=True, color='blue')
plt.title("Histogram with KDE")
plt.show()

2.2 Box Plot (Detecting Outliers)


tips = sns.load_dataset('tips')

plt.figure(figsize=(6, 4))
sns.boxplot(x=tips['total_bill'])
plt.title("Box Plot of Total Bill")
plt.show()

2.3 Pair Plot (Exploring Relationships)


sns.pairplot(tips, hue='sex')
plt.show()

2.4 Heatmap (Correlation Analysis)


corr_matrix = tips.corr()

plt.figure(figsize=(7, 5))
sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt=".2f")
plt.title("Correlation Heatmap")
plt.show()
3. Pyplot
3.1 Interactive Line Plot
import plotly.express as px

df = pd.DataFrame({
"x": np.linspace(0, 10, 100),
"y": np.sin(np.linspace(0, 10, 100))
})

fig = px.line(df, x='x', y='y', title="Interactive Sine Wave")


fig.show()

3.2 Interactive Scatter Plot


fig = px.scatter(tips, x='total_bill', y='tip', color='sex', size='size', title="Total
Bill vs Tip")
fig.show()

3.3 Interactive 3D Scatter Plot


import plotly.graph_objects as go

fig = go.Figure(data=[go.Scatter3d(
x=tips['total_bill'],
y=tips['tip'],
z=tips['size'],
mode='markers',
marker=dict(size=5, color=tips['total_bill'], colorscale='Viridis')
)])

fig.update_layout(title="3D Scatter Plot of Total Bill, Tip & Size")


fig.show()

You might also like