Matplotlib Tutorial #2: Create a Plot

tech_plygrnd

TechPlygrnd

Posted on September 3, 2023

Matplotlib Tutorial #2: Create a Plot

In this blog, I will show you how to create a simple plot in Matplotlib.


Plot

Matplotlib has provided a method called plot from pyplot. This method requires two arguments, which are the collection of x-points and y-points respectively. Let me show you how to use it.

First of all, you have to import the required packages

import matplotlib.pyplot as plt
import numpy as np
Enter fullscreen mode Exit fullscreen mode

Next, create two arrays that define the points in the x and y coordinates

xpoints = np.array([0, 6])
ypoints = np.array([0, 255])
Enter fullscreen mode Exit fullscreen mode

I have defined two points from the above code: (0, 0) and (6, 255).
Then, plot xpoints and ypoints into the Matplotlib

plt.plot(xpoints, ypoints)
plt.show()
Enter fullscreen mode Exit fullscreen mode

The above code will show the following output

Matplotlib plot


Congratulations, you have just created a plot in Matplotlib. Thank you for reading this blog, and have a great day!

💖 💪 🙅 🚩
tech_plygrnd
TechPlygrnd

Posted on September 3, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Matplotlib Tutorial #3: Plot Without Line
datascience Matplotlib Tutorial #3: Plot Without Line

September 4, 2023

Matplotlib Tutorial #2: Create a Plot
datascience Matplotlib Tutorial #2: Create a Plot

September 3, 2023

NumPy Tutorial #14: Random
datascience NumPy Tutorial #14: Random

August 31, 2023

NumPy Tutorial #11: Array Search
datascience NumPy Tutorial #11: Array Search

August 28, 2023