Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
PRACTICAL 1
1. Plot a Simple histogram and bar plot and apply various customization
techniques.
CODE:
import matplotlib.pyplot as plt
data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
plt.hist(data, bins=4, color='white', edgecolor='black', alpha=0.7)
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Simple Histogram with Customizations (IT B 5568)')
plt.grid(False)
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
B. barplot:
CODE:
import matplotlib.pyplot as plt
categories = ['A', 'B', 'C', 'D']
values = [5, 7, 3, 8]
plt.bar(categories, values, color='black', edgecolor='black')
plt.xlabel('Category')
plt.ylabel('Value')
plt.title('Simple Bar Plot with Customizations (IT B 5568)')
plt.grid(axis='y')
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
C. Seaborn Histogram with KDE
CODE:
import seaborn as sns
import matplotlib.pyplot as plt
data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
sns.histplot(data, bins=4, kde=True, color='white',alpha=0.3)
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Seaborn Histogram with KDE (IT B 5568)')
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
D.
CODE:
import seaborn as sns
import matplotlib.pyplot as plt
categories = ['A', 'B', 'C', 'D']
values = [5, 7, 3, 8]
sns.barplot(x=categories, y=values, hue=categories, palette='Blues')
plt.xlabel('Category')
plt.ylabel('Value')
plt.title('Seaborn Bar Plot with Customizations (IT B 5568)')
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
E. Pandas Histogram with Customization
CODE:
import pandas as pd
import matplotlib.pyplot as plt
data = pd.Series([1, 2, 2, 3, 3, 3, 4, 4, 4, 4])
data.plot(kind='hist', bins=4, color='black', edgecolor='black', alpha=0.7)
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Pandas Histogram with Customizations (IT B 5568)')
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
F. Pandas barplot with Customizations
CODE:
import pandas as pd
import matplotlib.pyplot as plt
data = pd.Series([5, 7, 3, 8], index=['A', 'B', 'C', 'D'])
data.plot(kind='bar', color='white', edgecolor='black')
plt.xlabel('Category')
plt.ylabel('Value')
plt.title('Pandas Bar Plot with Customizations (IT B 5568)')
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
G. Plotly Histogram with Customizations
CODE:
import plotly.express as px
data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4,6,7,8,8,9,10]
fig = px.histogram(data, title='Plotly Histogram with Customizations (IT B 5568)',opacity=0.2)
fig.update_traces(marker_color='white', marker_line_color='black', marker_line_width=1.5)
fig.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
H. Plotly Barplot with Customizations
CODE:
import plotly.express as px
categories = ['A', 'B', 'C', 'D']
values = [5, 7, 3, 8]
fig = px.bar(x=categories, y=values, title='Plotly Bar Plot with Customizations (IT B 5568)',
labels={'x':'Category', 'y':'Value'})
fig.update_traces(marker_color='white', marker_line_color='black', marker_line_width=3)
fig.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
PRACTICAL 2
1. Create a simple plot and add ticks, labels, axes
A. SCATTER PLOT
CODE:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
fig, ax = plt.subplots()
ax.scatter(x, y, color='black')
ax.set_xlabel('X-as')
ax.set_ylabel('Y-axis')
ax.set_title('Simple Scatter Plot (IT B 5568)')
ax.set_xticks([1, 3, 5])
ax.set_yticks([2, 6, 10])
ax.set_xlim(0, 6)
ax.set_ylim(0, 9)
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
B. Bar plot
CODE:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
fig, ax = plt.subplots()
ax.bar(x, y, color='black')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_title('Simple Bar Plot (IT B 5568)')
ax.set_xticks([1, 3, 5])
ax.set_yticks([2, 6, 10])
ax.set_xlim(0, 6)
ax.set_ylim(0, 15)
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
PRACTICAL 3
1. Plot Strip plot, Box Plot, Swarm plot, Joint plot, on Tips dataset.
a. Strip Plot of Total Bill by Day
CODE:
import seaborn as sns
import matplotlib.pyplot as plt
# Load the dataset
tips = sns.load_dataset('tips')
# Display the first few rows of the dataset
print(tips.head())
# Create a strip plot
plt.figure(figsize=(8, 6))
sns.stripplot(x='day', y='total_bill', data=tips)
plt.title('Strip Plot of Total Bill by Day (IT B 5568)')
plt.xlabel('Day')
plt.ylabel('Total Bill')
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
b. Box plot
CODE:
plt.figure(figsize=(8, 6))
sns.boxplot(x='day', y='total_bill', data=tips)
plt.title('Box Plot of Total Bill by Day (IT B 5568)')
plt.xlabel('Day')
plt.ylabel('Total Bill')
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
c. Swarm plot:
CODE:
plt.figure(figsize=(8, 6))
sns.swarmplot(x='day', y='total_bill', data=tips)
plt.title('Swarm Plot of Total Bill by Day (IT B 5568)')
plt.xlabel('Day')
plt.ylabel('Total Bill')
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
d. Joint plot
CODE:
sns.jointplot(x='total_bill', y='tip', data=tips, kind='hex')
plt.suptitle('Joint Plot of Total Bill and Tip (IT B 5568)', y=1.03)
plt.show()
OUTPUT:
Name: Ronit Manoj Thakur
Class: SY IT B
Roll no.: 5568
PRACTICAL 5
1. To add legend and annotation to the graph
CODE:
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 40]
plt.plot(x, y)
ax.annotate('Annotation Text', xy =(3 ,25),
xytext =(2,38),
arrowprops = dict
(facecolor ='orange',
shrink = 0.2 , lw=2 ))
plt.title('Annotation (IT B 5568)')
plt.show()
OUTPUT: