Your First Matplotlib Lab

MatplotlibMatplotlibBeginner
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 matplotlib(("`Matplotlib`")) -.-> matplotlib/BasicConceptsGroup(["`Basic Concepts`"]) matplotlib(("`Matplotlib`")) -.-> matplotlib/PlottingDataGroup(["`Plotting Data`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/DataScienceandMachineLearningGroup(["`Data Science and Machine Learning`"]) matplotlib/BasicConceptsGroup -.-> matplotlib/importing_matplotlib("`Importing Matplotlib`") matplotlib/BasicConceptsGroup -.-> matplotlib/figures_axes("`Understanding Figures and Axes`") matplotlib/PlottingDataGroup -.-> matplotlib/line_plots("`Line Plots`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/ModulesandPackagesGroup -.-> python/importing_modules("`Importing Modules`") python/DataScienceandMachineLearningGroup -.-> python/numerical_computing("`Numerical Computing`") python/DataScienceandMachineLearningGroup -.-> python/data_visualization("`Data Visualization`") subgraph Lab Skills matplotlib/importing_matplotlib -.-> lab-92737{{"`Your First Matplotlib Lab`"}} matplotlib/figures_axes -.-> lab-92737{{"`Your First Matplotlib Lab`"}} matplotlib/line_plots -.-> lab-92737{{"`Your First Matplotlib Lab`"}} python/tuples -.-> lab-92737{{"`Your First Matplotlib Lab`"}} python/importing_modules -.-> lab-92737{{"`Your First Matplotlib Lab`"}} python/numerical_computing -.-> 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
lab-hello-world-1-1

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()
lab-hello-world-1-2

Summary

Coungratulations! 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!

Other Matplotlib Tutorials you may like