Paint the Picture
Learn to visualize a single variable using bar charts, box plots, and histograms.
We'll cover the following...
We explored key statistics that describe a single variable—its center, spread, and shape. While these numerical summaries give us important insights, they can sometimes feel abstract and tough to interpret quickly. This time, we’ll bring those numbers to life with visualizations that make the data’s story clear and intuitive.
In this lesson, we’ll focus on simple yet powerful charts that reveal the distribution and characteristics of individual variables. These visuals help us spot patterns, uncover outliers, and notice subtle details that raw numbers might hide. Mastering these univariate visuals, we can better understand and communicate each variable’s unique story.
Picking the right univariate chart
Visualizing a single variable effectively depends on understanding its type and what aspect we want to explore. Numerical variables invite charts revealing their distribution, spread, and extremes, while categorical variables are best shown with charts highlighting category frequencies.
Choosing the right chart helps us unlock insights quickly and communicate data stories. Let’s explore three common univariate visualization types—each paired with practical code examples so we can try them out as we learn.
Bar chart
A bar chart is used to visualize categorical data by showing the frequency or count of each category as bars. It’s ideal when we want to compare values across distinct groups like product types, departments, or survey responses.
What a bar chart does:
Takes a categorical variable (e.g., product type, city, or grade).
Counts how many observations fall into each category.
Displays this as vertical bars, with bar height representing frequency.
Syntax
To create a bar chart in Python, we use plt.bar() from the matplotlib.pyplot module:
matplotlib.pyplot.bar(x, height, width=0.8, bottom=0, align='center', color=None, edgecolor=None, linewidth=None, label=None, zorder=None, **kwargs)
Common parameters
x: Sequence of scalars for the x-coordinates of the bars.height: Sequence of scalars for the height of each bar.width(Optional): Width of the bars (default is0.8).bottom(Optional): Y-coordinate where bars start (default is0).align(Optional): Bar alignment on the x-axis ('center'or'edge', default is'center').color(Optional): Fill color of the bars.edgecolor(Optional): Color of the bar borders.linewidth(Optional): Width of the bar borders.label(Optional): Label used in the legend.zorder(Optional): Drawing order of the bars relative to other elements. ...