An introduction to data visualization with Matplotlib


Businesses have always generated and collected data and used it to evaluate the competitive landscape, where they fit in it, and what their future could look like. Until recently, these data were mostly stored in physical filing cabinets, where the organization and maintenance process was complex and time-consuming. Now that businesses store all of this information digitally, they face different issues.

There’s a lot of work involved in gleaning business-advancing insights from data — so much so that it often requires the use of specialized tools.

Plus, the Data Analysts, consultants, and researchers that work with this data may understand the results in their raw format, but they need to present this information to non-technical stakeholders. To do so, they use Python and its 2D and 3D data visualization libraries called Matplotlib.

What is data visualization?

Pictures have been used to understand data for centuries now. After all, a map is a form of data visualization, and the pie chart was invented in the early 1800s.

Technology truly changed things, though. Computers make it possible to process large amounts of data quickly, which is great because more data is generated now than ever before. In fact, in 2021, people created 1.7 MB of data every second — and in this data lies the potential for great opportunities and insights.

There are many ways these insights can be communicated to others. Spreadsheets and tables are great for transferring data and insights between technically inclined people, but they definitely don’t work for everyone.

Charts, graphs, plots, and other graphical representations of data can turn these insights into something anyone can understand. They also make it easier to absorb the information, make faster decisions, and act on the insights quickly.

Data visualization techniques

In the early days, spreadsheets were one of the most common tools used to visualize data. With a spreadsheet, you can turn data into a table, bar graph, or pie chart. While these still work in many cases, they only go so far. Here are some of the many data visualization techniques a Data Scientist may use to turn data into graphics:

  • Scatter plots: This technique displays the relationship between two variables. A scatter plot uses an x and y-axis with dots to represent data points.
  • Line chart: This is a very common and basic data visualization technique. Line charts display how variables can change over time.
  • Area charts: This visualization method is a variation of a line chart. It can display multiple values in a time series or a sequence of data collected at equally spaced points in time.
  • Treemaps: This technique shows hierarchal data in a nested format. Each data point is represented as a rectangle, and the size of each rectangle is proportional to its percentage of the whole.

For these and other data visualization techniques, a spreadsheet won’t do — you need a tool like Matplotlib.

Why Data Scientists love Matplotlib

Matplotlib is a cross-platform data visualization and graphical plotting library for Python. Many developers consider Python to be one of the most accessible modern programming languages because its syntax is similar to a natural language. This makes Python a perfect language for beginners.

Matplotlib can be installed on a Windows, Mac, or Linux system running Python with one command. Matplotlib follows in the footsteps of Python by being simple to use. Using Matplotlib, a Data Scientist only needs a few lines of code in most cases to generate a visual data plot and run the results instantly.

Once those results are displayed, you don’t just get high-quality, publication-ready graphics (though that would be enough to choose Matplotlib). Matplotlib also generates a user interface with a menu structure that you can use to customize the plot, pan, zoom, and toggle various elements.

Matplotlib also works hand in hand with another powerful Python library, NumPy. NumPy is used for scientific programming in Python and can handle huge multi-dimensional arrays quickly and efficiently. You can quickly turn raw unstructured data into clean, structured data with NumPy and then use Matplotlib to turn it into graphics anyone can understand.

Another tool that works well with Matplotlib to make handling big data a breeze is pandas. pandas turns data into a fast in-memory 2D table object called a DataFrame. pandas DataFrames can be filtered, queried, segmented, and segregated quickly with a simple syntax and fed to Matplotlib to provide different insights into a business’s health and future.

These features make Matplotlib a universal tool for creating quality graphics from any type and size of data. But don’t take our word for it. Check out our Facebook Messenger analysis to see how Matplotlib can be used to analyze Facebook chat data and gain an understanding of the relationship between Facebook friends. You could also take a look at our Song Lyric Topic Analysis Livestream to learn how Matplotlib can be used with natural language processing to gain insights into popular music lyrics.

Getting started with data visualization

When a business uses the data it collects correctly, it can change its future. A Data Scientist will use a lot of processes to gather these insights from this data, and one of the most important is data visualization. When data is presented visually, it can tell its story to people from all walks of life.

To get started with data visualization, you can’t go wrong by choosing Matplotlib. If you already know Python, our Learn Data Visualization with Python course will teach you the Matplotlib skills that businesses are looking for. If you don’t know Python, no worries. Our Visualize Data with Python Skill Path will make you a Matplotlib expert, teaching you how to program in Python and how to use it for data analysis.

To use your data visualization skills in the financial industry, check out our Analyze Financial Data with Python course. And to make handling big data with Matplotlib even easier, try Learn Data Analysis with pandas.

Related articles

7 articles

What is C# ​U​sed ​F​or? 

4 minutes
By Codecademy Team

C# is a popular programming language that’s similar to C and C++. Learn what it’s used for, what you can do with it, and how to get started.