Matplotlib

Introduction to Matplotlib


What is Matplotlib?

This page covers an introduction to matplotlib tutorial.

Matplotlib is a comprehensive library for creating static, animated, and interactive visualisations in Python. It’s one of the most widely used plotting libraries in the Python ecosystem. Its fame expands particularly in the field of data science and scientific computing. Matplotlib provides a wide variety of plotting functions to generate various types of plots, including line plots, scatter plots, bar plots, histograms, 3D plots, and many more. It offers fine-grained control over almost every aspect of a plot. Such control allows users to customise the appearance of their visualisations to suit their specific needs.

Additionally, Matplotlib seamlessly integrates with other Python libraries such as NumPy and Pandas. As a result, the combination creates a powerful tool for data analysis and visualisation.

Why use matplotlib?

  • Flexibility: high degree of flexibility, allowing users to create a wide range of plots with extensive customisation options. Whether you need simple line plots or complex 3D visualisations, Matplotlib provides the tools to create them.
  • Wide Adoption: one of the most popular plotting libraries in the Python ecosystem. Its widespread adoption means there’s extensive documentation, tutorials, and community support available. This creates easiness for users to get help and resources when needed.
  • Integration: integration with other Python libraries commonly used in data analysis and scientific computing, such as NumPy, Pandas, and SciPy. This integration makes it easy to plot data stored in these libraries and combine Matplotlib visualisations with other analysis tasks.
  • Quality Plots: generating high-quality plots suitable for publication in academic journals, presentations, reports, and other professional settings. It provides precise control over plot elements like fonts, colors, line styles, and annotations. As a result, ensuring the resulting visualisations meet publication standards.
  • Customisation: customise every aspect of a plot, from the axis labels to the legend placement to the overall style. This level of customisation enables users to create plots that effectively communicate their data and insights in a visually appealing manner.
  • Interactivity: functionality for adding interactive elements to visualisations using tools like Matplotlib Widgets and Matplotlib Animation. These features enable users to create dynamic plots that respond to user interactions, enhancing the exploratory data analysis experience.
  • Cross-Platform Compatibility: compatible with various operating systems, including Windows, macOS, and Linux. As such, it makes the library accessible to a wide range of users regardless of their preferred development environment.

How to install matplotlib?

We can install Matplotlib using either pip or Anaconda, depending on the Python environment and preferences.

1. Installing Matplotlib with pip

If Python is already installed on the system, we can use pip, the Python package manager, to install Matplotlib. Open a terminal or command prompt and run the following command.

pip install matplotlib

This command will download and install the latest version of Matplotlib and its dependencies from the Python Package Index (PyPI). Once the installation is complete, we can start using Matplotlib in our Python scripts or interactive sessions.

2. Installing Matplotlib with Anaconda

Anaconda is a popular Python distribution that comes with many pre-installed scientific computing packages, including Matplotlib. If using Anaconda, we can install Matplotlib using the following command in our terminal or Anaconda Prompt.

conda install matplotlib

This command will install Matplotlib and its dependencies from the Anaconda repository.

After installing Matplotlib via either pip or Anaconda, we can verify the installation by importing Matplotlib in a Python script or interactive session.

import matplotlib

print(matplotlib.__version__)

This will print the version of Matplotlib installed on the system, confirming that the installation was successful.


This is an original introduction to matplotlib tutorial. Created by aicorr.com.

Next: Getting Started with Matplotlib