Your First Matplotlib Lab

PythonPythonBeginner
Practice Now

Introduction

Hi there, welcome to LabEx! In this first lab, you'll learn the classic "Hello, World!" program in Matplotlib.

Click the Continue button below to start the lab.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("Python")) -.-> python/ModulesandPackagesGroup(["Modules and Packages"]) python(("Python")) -.-> python/DataScienceandMachineLearningGroup(["Data Science and Machine Learning"]) python/ModulesandPackagesGroup -.-> python/importing_modules("Importing Modules") python/ModulesandPackagesGroup -.-> python/using_packages("Using Packages") python/DataScienceandMachineLearningGroup -.-> python/data_visualization("Data Visualization") subgraph Lab Skills python/importing_modules -.-> lab-92737{{"Your First Matplotlib Lab"}} python/using_packages -.-> lab-92737{{"Your First Matplotlib Lab"}} python/data_visualization -.-> lab-92737{{"Your First Matplotlib Lab"}} end

Hello Matplotlib

Let's start by importing the Matplotlib library. Open a new terminal and type:

python3
Python interpreter terminal window

This will open a Python interpreter. Now, let's import the Matplotlib library:

import matplotlib.pyplot as plt

Now, let's create a NumPy array with 1000 values between 0 and 2ฯ€:

import numpy as np
x = np.linspace(0, 2*np.pi, 1000)

Now, let's create a plot and show it:

plt.plot(x, np.sin(x))
plt.show()
sine wave plot example

Summary

Congratulations! You have completed your first LabEx Lab.

If you want to learn more about LabEx and how to use it, you can visit our Support Center . Or you can watch the video to learn more about LabEx.

Programming is a long journey, but Next Lab is just one click away. Let's do it!