Importing Libraries:
import seaborn as sns
import matplotlib.pyplot as plt
seaborn is a statistical data visualization library that is built on top of matplotlib.
matplotlib.pyplot is a module for creating static visualizations.
Loading the Titanic Dataset:
data = sns.load_dataset('titanic')
The sns.load_dataset() function loads built-in datasets available in Seaborn.
'titanic' is a dataset containing information about Titanic passengers, including their class, age, gender, fare, and survival status.
Creating a Count Plot:
sns.countplot(x='class', data=data)
sns.countplot() is used to plot the number of occurrences of categorical data.
x='class' specifies that the plot will display the count of passengers for each class (First, Second, and Third).
data=data indicates that the plot uses the Titanic dataset.
Displaying the Plot:
plt.show()
plt.show() renders and displays the plot using matplotlib.
Final Output:
3
0 Comments:
Post a Comment