61/90: Learn Core Python in 90 Days: A Beginner’s Guide

criesin.90days
2 min readOct 21, 2023

--

Day 61: Exploring Matplotlib’s Basic Plot Types

Welcome to Day 61 of our 90-day journey to learn core Python! In our previous posts, we’ve discussed web development, testing, Flask extensions, deployment, logging, web scraping, web scraping ethics, and data visualization with Matplotlib. Today, we’re going to dive deeper into Matplotlib and explore its basic plot types.

Basic Plot Types in Matplotlib

Matplotlib offers a wide range of plot types to visualize different types of data. Here are some of the fundamental plot types you’ll commonly use:

1. Line Plot

A line plot is used to represent data points as individual markers connected by lines. It’s suitable for showing trends over a continuous interval or time series data.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [10, 12, 5, 8, 3]

plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Plot')
plt.show()

2. Bar Chart

A bar chart displays data using rectangular bars with lengths proportional to the values they represent. It’s great for comparing categories or discrete data.

import matplotlib.pyplot as plt

categories = ['A', 'B', 'C', 'D']
values = [15, 7, 10, 12]

plt.bar(categories, values)
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Bar Chart')
plt.show()

3. Scatter Plot

A scatter plot represents individual data points as dots on a two-dimensional plane. It’s useful for visualizing the relationship between two continuous variables.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [10, 12, 5, 8, 3]

plt.scatter(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot')
plt.show()

4. Histogram

A histogram displays the distribution of a dataset by dividing it into bins and counting the number of data points in each bin. It’s used for visualizing the data’s frequency distribution.

import matplotlib.pyplot as plt

data = [1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6]

plt.hist(data, bins=6, edgecolor='k')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Histogram')
plt.show()

These are just a few examples of the basic plot types in Matplotlib. As you explore and work with more data, you’ll discover how to choose the most suitable plot type for your specific needs.

Real-World Applications

Basic plot types are the building blocks of data visualization. They are used in countless real-world scenarios, from visualizing sales data and stock prices to tracking environmental changes and scientific experiments.

Conclusion

Congratulations on reaching Day 61 of our Python learning journey! Today, we delved into Matplotlib’s basic plot types, including line plots, bar charts, scatter plots, and histograms. We discussed how each plot type is used and provided examples to get you started.

As you continue to learn and work with data visualization, practice creating these basic plot types with your own datasets. In the coming days, we’ll explore advanced plotting techniques and customization options to take your data visualization skills to the next level.

Keep up the great work, and let’s continue to paint a vivid picture of our data with Matplotlib! 🚀

Note: This blog post is part of a 90-day series to teach core Python programming from scratch. You can find all previous days in the series index here.

--

--

criesin.90days

Welcome to our 90-day journey to learn a skill! Over the next three months, this guide is designed to help you learn Python from scratch.