DEV Community

TechPlygrnd
TechPlygrnd

Posted on

1

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!

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

If you found this post useful, please drop a ❤️ or leave a kind comment!

Okay