DEV Community

TechPlygrnd
TechPlygrnd

Posted on

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!

Top comments (0)