Matplotlib Tutorial #2: Create a Plot
TechPlygrnd
Posted on September 3, 2023
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
Next, create two arrays that define the points in the x and y coordinates
xpoints = np.array([0, 6])
ypoints = np.array([0, 255])
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()
The above code will show the following output
Congratulations, you have just created a plot in Matplotlib. Thank you for reading this blog, and have a great day!
Posted on September 3, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.