Contents
Visualizing Distributions
Understanding how values are spread is key to good analysis. Different plots show the shape in different ways. This topic goes beyond the basic histogram and shows how to compare distributions across groups.
a. Histograms and KDE Plots
A histogram shows counts in bins. A Kernel Density Estimate, or KDE, plot draws a smooth curve that estimates the shape of the distribution. It makes the overall pattern easier to see.
sns.histplot(data=tips, x="total_bill", kde=True, bins=20)
sns.kdeplot(data=tips, x="total_bill", fill=True)The KDE curve is useful for spotting peaks. A distribution with two peaks is called bimodal and often means that two different groups are mixed in the data.
Histograms are more honest about the raw counts, while KDE plots are better for comparing shapes. Using both together gives a complete picture.
b. Violin Plots
A violin plot combines a box plot with a KDE. Its width at each height shows how many values lie there. This reveals the shape of the distribution, which a box plot alone hides.
sns.violinplot(data=tips, x="day", y="total_bill", inner="quartile")The inner option shows the quartiles inside the violin. You can also use split=True with a hue of two categories to compare them in one shape.
Violin plots work best with enough data points. With very small samples, the smooth shape can suggest detail that is not really there.
c. ECDF Plots
The Empirical Cumulative Distribution Function, or ECDF, plot shows the share of values that fall at or below each point. It looks like a rising staircase from 0 to 1.
sns.ecdfplot(data=tips, x="total_bill", hue="time")ECDF plots have no bins and no smoothing, so they show every data point honestly. They are very good for comparing two or more groups, since the curves can be placed on the same chart.
You can read values directly from them. For example, you can find the median by looking where the curve reaches 0.5.
d. Comparing Distributions Across Groups
To compare groups, choose a chart that keeps the scale shared. Overlapping KDE plots, side-by-side box or violin plots, and faceted histograms are all good choices.
sns.kdeplot(data=tips, x="total_bill", hue="day", common_norm=False)
sns.boxplot(data=tips, x="day", y="total_bill")Look at three things: the center, the spread, and the shape. Does one group have a higher median? Is one more spread out? Does one have outliers?
Avoid too many overlapping groups, since they hide each other. If you have more than four or five groups, use separate small charts or side-by-side plots instead.
Data Visualization Tutorial
Wesline Rinisha








