Complete this TODO by finishing the subplot of box plots using Seaborn and Matplotlib. Use the below image to check your output as no todo_check() is given. Define a subplot using matplotlibs subplots() function. Store the output into two variables: fig and axs. Here, the axs variable will hold all our subplot grids which will determine which subplot we plot to. See docs for more help regarding subplots. Pass the following arguments that correspond to the below descriptions: The subplot should have 11 row and 1 column, meaning there will be 11 total subplots. See the arguments in the docs that refer to setting the number of rows and columns! Additionally, you will need to pass the keyword argument (kwarg) figsize (this is not listed directly in the docs). This should be equal to (20, 30) as this will ensure our plot will make all the subplots big enough to be readable. Here 20 (index 0) is the width and 30 (index 1) is the height. Feel free to increase the width/height if it is too small for you. Use Seaborn's boxplot() function to create a box plot for each of our numerical features. Call the boxplot() function using Seaborn and pass the following arguments: Pass the keyword argument x which takes the current numerical feature's data. Do so by indexing forestfire_df using the current feature numerical feature's column name stored in column_name. Pass the keyword argument (kwarg) ax which determines which subplot to plot to. Do so by passing the axs indexed by idx. idx represents the current subplot index we are currently on! See docs for box plot. import seaborn as sns import matplotlib.pyplot as plt # Gets all the numerical feature data numerical_features = forestfire_df.drop(['day', 'month'], axis=1) numerical_features # TODO 2.1 fig, axs = # We flatten the axs variable as it would be a 2D array making it # harder to index axs = axs.flatten() # Index refers to the current index of the numerical feature columns for idx, column_name in enumerate(numerical_features.columns): # TODO 2.2 # Sets the x-axis title for each subplot axs[idx].set_xlabel(axs[idx].get_xlabel(), fontsize=15) # Formats subplots so they overlap less fig.tight_layout() # Shows entire plot once done plt.show()
TODO 2
Complete this TODO by finishing the subplot of box plots using Seaborn and Matplotlib. Use the below image to check your output as no todo_check() is given.
-
Define a subplot using matplotlibs subplots() function. Store the output into two variables: fig and axs. Here, the axs variable will hold all our subplot grids which will determine which subplot we plot to. See docs for more help regarding subplots. Pass the following arguments that correspond to the below descriptions:
- The subplot should have 11 row and 1 column, meaning there will be 11 total subplots. See the arguments in the docs that refer to setting the number of rows and columns!
- Additionally, you will need to pass the keyword argument (kwarg) figsize (this is not listed directly in the docs). This should be equal to (20, 30) as this will ensure our plot will make all the subplots big enough to be readable. Here 20 (index 0) is the width and 30 (index 1) is the height. Feel free to increase the width/height if it is too small for you.
-
Use Seaborn's boxplot() function to create a box plot for each of our numerical features. Call the boxplot() function using Seaborn and pass the following arguments:
- Pass the keyword argument x which takes the current numerical feature's data. Do so by indexing forestfire_df using the current feature numerical feature's column name stored in column_name.
- Pass the keyword argument (kwarg) ax which determines which subplot to plot to. Do so by passing the axs indexed by idx. idx represents the current subplot index we are currently on! See docs for box plot.
import seaborn as sns
import matplotlib.pyplot as plt
# Gets all the numerical feature data
numerical_features = forestfire_df.drop(['day', 'month'], axis=1)
numerical_features
# TODO 2.1
fig, axs =
# We flatten the axs variable as it would be a 2D array making it
# harder to index
axs = axs.flatten()
# Index refers to the current index of the numerical feature columns
for idx, column_name in enumerate(numerical_features.columns):
# TODO 2.2
# Sets the x-axis title for each subplot
axs[idx].set_xlabel(axs[idx].get_xlabel(), fontsize=15)
# Formats subplots so they overlap less
fig.tight_layout()
# Shows entire plot once done
plt.show()
Trending now
This is a popular solution!
Step by step
Solved in 2 steps