DVST practicle finalll
DVST practicle finalll
( DATA VISUALIZATION)
SUBMITTED BY
ROLL NO
(SDMSDS028)
(MEGHNA SINGH)
ACADEMIC YEAR
2023-2024
CERTIFICATE
- This is to certify that Mr AJAY ASHOK GOUND, Roll number SDMSDS028 of M.Sc.
Data Science Part-II Semester III (2023 - 2024) has successfully completed the
report on Data Visualization as per the guidelines of
KES’ Shroff College of Arts and Commerce, Kandivali(W), Mumbai- 400067
Output:
Practical 2
Histograms
Code:
import matplotlib.pyplot as plt
import numpy as np
data=np. random.randn(1000)
plt.hist(data, bins = 20, edgecolor = 'black')
plt.title('Histogram')
plt.xlabel('value')
plt.ylabel('frequency')
plt.show()
Ouput:
Practical 3
Density Charts
a. Kernel Density Plot: Kernel density plots show the estimated probability density of a
continuous variable.
Code:
import seaborn as sns
import matplotlib.pyplot as plt
data = sns.load_dataset('iris')
sns.kdeplot(data=data['sepal_length'], shade=True)
plt.title('Keranl Density plot of Sepal Length')
plt.xlabel('Sepal length')
plt.ylabel('Density')
plt.show()
Output:
b. 2D Density Plot: 2D density plots show the distribution of two continuous variables
as a heatmap
Code:
import seaborn as sns
import matplotlib.pyplot as plt
data = sns.load_dataset('iris')
sns.kdeplot(data=data, x='sepal_length',y='sepal_width',cmap='Blues', fill=True)
plt.title('2D Density plot of Sepal Lengt vs Sepal Width')
plt.xlabel('Sepal length')
plt.ylabel('Sepal Width')
plt.show()
Output:
Practical 4
Simple and Multiple Bar Charts
Code:
import matplotlib.pyplot as plt
categories = ['Category A','Category B', 'Category C', 'Category D']
values = [15,30,25,40]
plt.bar(categories,values)
plt.title('Simple Bar Chart')
plt.xlabel('Categories')
plt.ylabel('Values')
plt.show()
Output:
b. multiple bar chart
Code:
import numpy as np
categories = ['Category A','Category B', 'Category C', 'Category D']
values1 = [15,30,25,40]
values2 = [20,25,35,15]
x = np.arange(len(categories))
width = 0.4
Output:
Practical 5
Pie Charts
Code:
import matplotlib.pyplot as plt
labels = ['Category A','Category B', 'Category C', 'Category D']
sizes = [25,40,15,20]
plt.figure(figsize=(6,6))
plt.pie(sizes,labels=labels, autopct='%1.1f%%', startangle=140)
plt.axis('equal')
plt.title('Simple Pie Chart')
plt.show()
Output:
Practical 6
Code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
data = {
'Category' : ['A','B','A','C','B','C','A','B','C'],
'X': np.random.randn(9),
'Y': np.random.randn(9)
}
df = pd.DataFrame(data)
plt.figure(figsize=(8,6))
plt.scatter(df['X'], df['Y'], c='blue', marker='o')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter Plot')
plt.show()
Output:
Code:
plt.figure(figsize=(8,6))
sns.scatterplot(data=df, x='X', y='Y', hue='Category',palette='Set1', marker='o')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter Plot with Categories')
plt.legend()
plt.show()
plt.figure(figsize=(8,6))
sns.boxplot(data=df, x='Category', y='X',palette='Pastel1')
plt.xlabel('Category')
plt.ylabel('X')
plt.title('Box Plot')
plt.show()
Output:
Code:
plt.figure(figsize=(8,6))
sns.violinplot(data=df, x='Category', y='Y',palette='Set2')
plt.xlabel('Category')
plt.ylabel('Y')
plt.title('Violin Plot')
plt.show()
Output:
Practical 7
Code:
import matplotlib.pyplot as plt
x=[1,2,3,4,5]
y=[10,12,8,15,11]
Output:
Practical 8
Overriding Aesthetics
Code:
import matplotlib.pyplot as plt
import numpy as np
# Generate some data
x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots()
Output:
Practical 9
Facets and Themes
Code:
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
# Create a facet grid
g = sns.FacetGrid(tips, col="time", row="sex")
g.map(sns.scatterplot, "total_bill", "tip")
Output:
Code:
import plotly.express as px
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", facet_col="time", facet_row="sex")
# Customize the layout and appearance
fig.update_xaxes(title_text="Total Bill ($)")
fig.update_yaxes(title_text="Tip ($)")
fig.update_layout(
xaxis=dict(range=[0, 60]),
yaxis=dict(range=[0, 12]),
)
fig.show()
Output:
Practical 10
Introduction to Matplotlib Package in Python
Code:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
# Add labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Line Plot using Matplotlib')
plt.show()
Output:
Practical 11
Plotting and Controlling Graphs
Code:
import matplotlib.pyplot as plt
x=[1,2,3,4,5]
y=[10,15,13,18,20]
x_range=[0,6]
y_range=[0,25]
plt.figure(figsize=(6, 3))
plt.plot(x,y)
plt.xlim(x_range)
plt.ylim(y_range)
plt.title("Plotting and Controlling Graphs")
plt.xlabel("X-axix")
plt.ylabel("Y-axis")
plt.savefig("pc1.png")
plt.show()
Output:
Practical 12
Adding Text to Graphs
Code:
import matplotlib.pyplot as plt
# Create some sample data
x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]
# Create a plot
plt.plot(x, y)
# Add text to the graph
plt.text(2, 7, 'y=2x+b', fontsize=12, color='red')
Output:
Practical 13
Getting and Setting Values in Graphs
Code:
import matplotlib.pyplot as plt
# Create some sample data
x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]
# Create a plot
plt.plot(x, y)
# Create a plot
plt.plot(x, y)
Output: