Untitled 18
Untitled 18
Untitled 18
3
AIM- Study Different Basic Functions of Matplotlib and
Seaborn Libraries
1. Represent a bar graph of the categorical feature of the student_result.csv dataset
In [18]:
import pandas as pd
import matplotlib.pyplot as plt
plt.bar(result_counts.index, result_counts.values)
plt.xlabel('Result')
plt.ylabel('Count')
plt.title('Distribution of Student Results')
plt.show()
2.Display the marks of the last 10 students of the subject- ‘Maths’ and depict them using a bar graph (The name
of those students are as mentioned- ‘Raj, Sanjay, Abhisekh, John, Saurav, Sikha, Gayatri, Nisha, Mahesh,
Parvati’
In [19]:
import pandas as pd
import matplotlib.pyplot as plt
plt.show()
3.Represent a subplot for the above students and the last 10 marks for three subjects- ‘English, Math, and
Bangla’. Use appropriate legend, Title, etc for each graph
In [20]:
import pandas as pd
import matplotlib.pyplot as plt
# Create subplots
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(15, 5))
plt.tight_layout()
plt.show()
Loading [MathJax]/extensions/Safe.js
1. Draw a Histogram as per the following detailsa. X-axis- 20 random values (between 10 and 100) b. Y axis-
bins should be – 5,10,15,20,25 c. Histtype=’stepfill’ d. Edge= Red
In [22]:
import numpy as np
import matplotlib.pyplot as plt
# Create a histogram
plt.hist(random_values, bins=bin_edges, histtype='stepfilled', edgecolor='red', alpha=0.7)
plt.xlabel('Values')
plt.ylabel('Frequency')
plt.title('Histogram of 20 Random Values')
plt.xticks(bin_edges)
plt.tight_layout()
plt.show()
1. Create two subplots of sepal width vs sepal length and petal length vs petal width. The subplots should be
in red and blue colors respectively
In [24]:
import seaborn as sns
Loading [MathJax]/extensions/Safe.js
import matplotlib.pyplot as plt
# Load the Iris dataset
iris = sns.load_dataset("iris")
plt.tight_layout()
plt.show()
1. Plot a pie chart using the following dataa. Subject Name= DAA, DBE, ML, DS, DL b. Subject_Mark=
90,70,78,45,68 NOTE- Use different colors for each slice
In [25]:
import matplotlib.pyplot as plt
Loading [MathJax]/extensions/Safe.js
1. Plot a pie chart using the following dataa. Subject= English, Odia, Hindi, Geography, Maths b. Study_hour=
4,8,6,2,4 NOTE- Use different colors for each slice
In [26]:
import matplotlib.pyplot as plt
1. Plot a color map on the 3D surface using the following dataa. cmap= RdYlBl b. Values of the X and Y axis
should be between -1 to 1, stepping value should be 0.25
In [27]:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Create a colormap
cmap = plt.get_cmap('RdYlBu')
# Add colorbar
cbar = fig.colorbar(surf, ax=ax, shrink=0.5, aspect=10)
cbar.set_label('Z values')
plt.show()
1. Draw two different graphs using the species feature of the IRIS dataset using Matplotlib and Seaborn.
Mention key differences between them. (Represent both the graph within the same graph)
In [28]:
import seaborn as sns
import matplotlib.pyplot as plt
# Matplotlib Scatterplot
plt.subplot(1, 2, 1)
for species in iris['species'].unique():
subset = iris[iris['species'] == species]
Loading [MathJax]/extensions/Safe.js
plt.scatter(subset['sepal_length'], subset['sepal_width'], label=species)
plt.title('Matplotlib Scatterplot')
plt.xlabel('Sepal Length')
plt.ylabel('Sepal Width')
plt.legend()
# Seaborn Scatterplot
plt.subplot(1, 2, 2)
sns.scatterplot(data=iris, x='sepal_length', y='sepal_width', hue='species')
plt.title('Seaborn Scatterplot')
plt.xlabel('Sepal Length')
plt.ylabel('Sepal Width')
plt.tight_layout()
plt.show()
1. Draw a correlation heatmap using all the numerical features (sepal length, sepal width, petal length, petal
width) of the IRIS dataset using Matplotlib and Seaborn. Mention key differences between them. (Represent
both the graph within the same graph)
In [29]:
import seaborn as sns
import matplotlib.pyplot as plt
plt.tight_layout()
plt.show()
NAME-KRITIKA DAS
ROLLNO-CSE21068
REGD NO-2101020068
In [ ]:
Loading [MathJax]/extensions/Safe.js