Mfds QnA
Mfds QnA
A. In Matplotlib, xlim() and ylim() are functions used to set or get the limits of
the x-axis and y-axis, respectively. Here are the key differences:
• xlim():
o Sets or gets the limits of the x-axis.
o Usage: xlim(min, max) or xlim() to get the current limits.
o Example: plt.xlim(0, 10) sets the x-axis range from 0 to 10.
• ylim():
o Sets or gets the limits of the y-axis.
o Usage: ylim(min, max) or ylim() to get the current limits.
o Example: plt.ylim(0, 20) sets the y-axis range from 0 to 20.
In essence, both functions serve similar purposes but are specific to their
respective axes.
11. What is a whisker plot, and how does it relate to a box plot?
• Box:
o The box itself represents the interquartile range (IQR), which is the
range between the first quartile (Q1) and the third quartile (Q3).
This middle 50% of the data is where the bulk of the values lie.
o A line inside the box indicates the median (Q2) of the dataset.
• Whiskers:
o The "whiskers" extend from the edges of the box to the smallest
and largest values within 1.5 * IQR from Q1 and Q3, respectively.
o Whiskers help to show the spread of the rest of the data.
• Outliers:
o Points outside the whiskers are considered outliers and are often
plotted as individual points.
The box plot is a powerful tool for detecting outliers and understanding the
spread and symmetry of the data. It allows quick comparisons between multiple
datasets and is widely used in exploratory data analysis.
15. Define what subplots and KDE are in the context of data visualization?
Subplots
Subplots refer to the technique of creating multiple plots within a single figure.
This is particularly useful when comparing multiple datasets or visualizing
different aspects of the same dataset side-by-side.
• Usage in Matplotlib:
o The subplot function allows you to specify the number of rows and
columns of subplots and their positions.
o Example: plt.subplot(2, 2, 1) creates a subplot grid with 2 rows and
2 columns and positions the current plot in the first cell.
• Purpose:
o Facilitates comparison and contrast between different datasets or
variables.
o Allows for a more organized and compact presentation of multiple
visualizations.
# Sample data
data = np.random.normal(size=1000)
# Creating subplots
fig, ax = plt.subplots(1, 2, figsize=(12, 5))
plt.show()
This example demonstrates how subplots can be used to place a histogram and a
KDE plot side by side for comparison.
19. Illustrate the importance of data visualization in data analysis and
explain about pairwise plot, violin plot and palette in seaborn.
Pairwise Plot
A pairwise plot (or pair plot) is a matrix of scatter plots used to visualize
pairwise relationships between multiple variables in a dataset.
# Load dataset
iris = load_dataset('iris')
sns.pairplot(iris, hue='species')
plt.show()
Violin Plot
A violin plot combines aspects of a box plot and a KDE plot. It shows the
distribution of the data across different categories.
# Load dataset
tips = sns.load_dataset('tips')
A palette in Seaborn refers to a set of colors used for the visual elements in a
plot.
# Load dataset
tips = sns.load_dataset('tips')
# Set a palette
sns.set_palette('husl')
Here’s how you can create and customize a KDE plot using Seaborn:
• Shade: Adds shading under the KDE curve for better visual appeal
(shade=True).
• Color: Changes the color of the KDE plot (color='r' for red).
• Bandwidth Adjustment: Adjusts the bandwidth of the KDE, affecting
the smoothness of the curve (bw_adjust=0.5 makes the curve less smooth,
bw_adjust=2 makes it smoother).
• Line Style: Changes the style of the KDE line (linestyle='--' for dashed
line).
• Line Width: Adjusts the width of the KDE line (linewidth=2 for thicker
line).
Example Code