0% found this document useful (0 votes)
5 views

DVST practicle finalll

The document is a report on Data Visualization submitted by Ajay Ashok Gound for his M.Sc. Data Science program. It includes practical exercises using various data visualization techniques in Python, such as scatter plots, histograms, bar charts, and pie charts. Each practical section contains code snippets and expected outputs demonstrating the application of these visualization methods.

Uploaded by

Zeddy Zayn
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)
5 views

DVST practicle finalll

The document is a report on Data Visualization submitted by Ajay Ashok Gound for his M.Sc. Data Science program. It includes practical exercises using various data visualization techniques in Python, such as scatter plots, histograms, bar charts, and pie charts. Each practical section contains code snippets and expected outputs demonstrating the application of these visualization methods.

Uploaded by

Zeddy Zayn
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/ 22

A REPORT ON

( DATA VISUALIZATION)

SUBMITTED BY

(AJAY ASHOK GOUND)

ROLL NO

(SDMSDS028)

M.SC DATA SCIENCE

(SEMESTER III) part-2

UNDER THE GUIDANCE OF

(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

Teacher In-charge Principal

Name & Signature Dr. L. Bhushan


Practical 1
Code:
ggplot(data = mtcars, aes(x = hp, y = mpg, col = disp)) +
geom_point() +
labs(title = "Miles per Gallon vs Horsepower",
x = "Horsepower",
y = "Miles per Gallon")

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

a. simple bar chart

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

plt.bar(x - width/2,values1, width, label='Values 1')


plt.bar(x + width/2,values2, width, label='Values 2')

plt.title('Multiple Bar Chart')


plt.xlabel('Categories')
plt.ylabel('Values')
plt.xticks(x,categories)
plt.legend()
plt.show()

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

 Factors and Aesthetics

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

 Plotting with Layers

Code:
import matplotlib.pyplot as plt
x=[1,2,3,4,5]
y=[10,12,8,15,11]

plt.scatter(x,y,label='Data Points', color ='blue')


plt.plot(x,y,label='Trendline',color='red', linestyle='--')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot with Layers')
plt.legend()
plt.show()

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()

# Customize the aesthetics


ax.plot(x, y, label='Sine Curve', color='red', linestyle='--', marker='o', markersize=8,
markerfacecolor='blue')

# Set axis labels and title


ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_title(Overriding Asthetics’)
ax.legend()
plt.show()

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")

g.set_axis_labels("Total Bill ($)", "Tip ($)")


g.set(xlim=(0, 60), ylim=(0, 12))
plt.show()

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')

# Customize other aspects of the plot


plt.title('Example Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
# Show the plot
plt.show()

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)

# Function to get mouse click coordinates


def onclick(event):
print(f"Clicked at x={event.xdata}, y={event.ydata}")

# Connect the click event to the figure


fig, ax = plt.subplots()
fig.canvas.mpl_connect('button_press_event', onclick)

# Show the plot


plt.show()

# Create some sample data


x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]
# Create a plot
plt.plot(x, y)

# Get the x and y data from the plot


x_data, y_data = plt.gca().lines[0].get_data()
print("X Data:", x_data)
print("Y Data:", y_data)
plt.show()

# Create some sample data


x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]

# Create a plot
plt.plot(x, y)

# Set a new value at index 2


new_y_value = 7
y[2] = new_y_value
# Redraw the plot with the updated data
plt.plot(x, y)
plt.show()

Output:

You might also like