
If you’re in any kind of data-facing role, whether if you’re a data analyst, data engineer, data scientist, or really anything data-related, you should be familiar with the matplotlib library.
🔥 Hot take: If you can’t visualize your data, then you don’t understand it.
I want to provide an overview of the 6 most common plots in matplotlib: line plots, scatter plots, bar charts, histograms, box plots, and pie charts, which are displayed below.

» If you want to see the source code of this plot, visit this GitHub gist.
1. Line Plot
A line plot connects data points with straight lines, making it ideal for showing trends over time or continuous data.
It's commonly used for time series data, showing how variables change over time, or displaying mathematical functions.
Line plots are particularly effective when you want to emphasize the relationship between consecutive data points. You can create a line plot by using the following one-liner:
plt.plot([1, 2], [1, 2])
2. Scatter Plot
A scatter plot displays individual data points as dots on a coordinate system without connecting them.
It's perfect for exploring relationships between two continuous variables, identifying correlations, outliers, or clusters in data.
Scatter plots are widely used in statistical analysis to visualize how one variable might relate to another. Similarly with scatter plots, call the scatter method:
plt.scatter([1, 5], [2, 3]) # plots at (1, 2) and (5, 3)
3. Bar Chart
Bar charts use rectangular bars to represent categorical data, with bar height or length corresponding to the data values.
They're excellent for comparing quantities across different categories, showing rankings, or displaying survey results.
Bar charts make it easy to compare values at a glance and are one of the most intuitive visualization types. Bar charts can be made with the following code:
hurricane_cats = ['cat 1', 'cat 2', 'cat 3', 'cat 4', 'cat 5']
n_hurricanes = [3, 5, 2, 1, 0]
plt.bar(categories, values)
4. Histogram
A histogram shows the distribution of a continuous variable by dividing data into bins and displaying the frequency of values in each bin as bars.
It's essential for understanding data distribution, identifying patterns like normal distribution or skewness, and spotting outliers.
Histograms help answer questions about how data is spread across different value ranges.
import numpy as np
data = np.random.normal(100, 15, 1000)
plt.hist(data)
5. Box Plot
A box plot (or box-and-whisker plot) provides a statistical summary of data distribution, showing the median, quartiles, and outliers in a compact format.
It's particularly useful for comparing distributions across different groups, identifying outliers, and understanding data spread.
Box plots excel at revealing the central tendency and variability of datasets, especially when comparing multiple groups side by side.
# Sample data
data1 = np.random.normal(0, 1, 100)
data2 = np.random.normal(1, 2, 100)
data3 = np.random.normal(2, 1.5, 100)
labels = ['Dataset A', 'Dataset B', 'Dataset C']
plt.boxplot([data1, data2, data3], labels=labels, notch=True)
6. Pie Chart
A pie chart displays data as slices of a circular "pie," where each slice represents a proportion of the whole.
It's ideal for showing the relative sizes of parts that make up a complete dataset, such as market share, budget allocation, or survey response percentages.
Pie charts are most effective when you have a small number of categories (typically 5-7) and want to emphasize how each part contributes to the total.
sizes = [15, 30, 45, 10]
labels = ['Cat A', 'Cat B', 'Cat C', 'Cat D']
colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue']
plt.pie(sizes, labels=labels, colors=colors)
Happy coding!
📧 Join the Python Snacks Newsletter! 🐍
Want even more Python-related content that’s useful? Here’s 3 reasons why you should subscribe the Python Snacks newsletter:
Get Ahead in Python with bite-sized Python tips and tricks delivered straight to your inbox, like the one above.
Exclusive Subscriber Perks: Receive a curated selection of up to 6 high-impact Python resources, tips, and exclusive insights with each email.
Get Smarter with Python in under 5 minutes. Your next Python breakthrough could just an email away.
You can unsubscribe at any time.
Interested in starting a newsletter or a blog?
Do you have a wealth of knowledge and insights to share with the world? Starting your own newsletter or blog is an excellent way to establish yourself as an authority in your field, connect with a like-minded community, and open up new opportunities.
If TikTok, Twitter, Facebook, or other social media platforms were to get banned, you’d lose all your followers. This is why you should start a newsletter: you own your audience.
This article may contain affiliate links. Affiliate links come at no cost to you and support the costs of this blog. Should you purchase a product/service from an affiliate link, it will come at no additional cost to you.