Visualizing Data in Python With Matplotlib
Learn how to effectively communicate complex datasets using Python and Matplotlib, a popular Python library for data visualization. With Matplotlib, you can create visualizations that reveal patterns, trends and anomalies that raw data alone may not expose. Matplotlib enables users to transform data points into a wide range of visual formats, including static, interactive and animated graphs and charts.
Versatile and highly customizable, Matplotlib is built on NumPy and seamlessly integrates with other scientific computing libraries in Python. Its ability to handle diverse visualization needs and deliver clear, impactful data insights makes Matplotlib a go-to tool among data scientists, engineers and researchers.
Get started With Matplotlib
If you don’t have Matplotlib installed on your machine, you can quickly install it using pip.
The next step is to import Matplotlib and its pyplot module, which provides a MATLAB-like interface for creating plots. MATLAB is a high-level programming language and environment designed for numerical computing, data analysis and visualization.
Matplotlib can reads from many different data structures, including tuples, NumPy Arrays, Pandas Series, and iterables. Regardless of the data structure, the visualization set follows a similar pattern. This tutorial focuses on creating static visualizations using lists.
Building a Line Plot
Line plots display data points connected by straight lines. Line plots reveal trends over time (e.g., stock price fluctuations, temperature readings). They also show relationships between variables (e.g., how much water a plant needs to reach optimal health).
To create a line plot:
1. Add the sample data.
2. Create the plot.
3. Add titles and labels. Show the plot.
Here’s what it looks like as one file:
It creates the following line plot:

Building a Bar Chart
Bar charts are effective for comparing different categories (e.g., product sales across various products, population size by location). Bar charts use rectangular bars, with the height of each bar proportional to its represented value.
The syntax for creating a bar chart is similar to that for line plots. The resulting bar chart is displayed accordingly.
Our bar chart looks like this:

Building Scatter Plots
Scatter plots represent individual data points on a two-dimensional plane, highlighting relationships between two variables (e.g., height and weight, hours studied and test scores). Scatter plots also reveal patterns, trends, and outliers within the data (e.g., correlation between temperature and ice cream sales, employee salaries vs. years of experience).
The code below creates the scatter plot: