Professional Documents
Culture Documents
Python. The process involved implementing a library to create several subplots arranged in a
grid-like format. Each subplot can exhibit various visualizations or depict distinct aspects of the
data. Below is the Python code utilized and the corresponding output.
—------------------------------------
import pandas as pd
df = pd.read_excel('titanic_data.xls')
#Creating a Multi-Graph
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(12, 8)) # Create a 2x2 grid of subplots
Class'].value_counts().values)
axs[0, 0].set_ylabel('Count')
axs[0, 1].set_xlabel('Age')
axs[0, 1].set_ylabel('Count')
# Subplot 3: Pie Chart of Survival Rate
survival_counts = df['Survived'].value_counts()
startangle=90)
plt.tight_layout()
plt.show()
—------------------------------------
To create a multi-graph using the "titanic_data.xls" dataset, we first load it using pd.read_excel()
and create a DataFrame named df. We then use plt.subplots() to specify the number of rows
(nrows) and columns (ncols) of subplots we want in the grid and set the overall size of the
Each subplot can display different visualizations. In this example, we have created four
subplots:
1. The passenger class distribution is shown using a bar plot in axs[0, 0].bar().
set_title(), set_xlabel(), set_ylabel(), etc. Finally, we use plt.tight_layout() to adjust the spacing