DEV Community

TechPlygrnd
TechPlygrnd

Posted on

1

Matplotlib Tutorial #4: Plot With Default X-Points

You actually don't have to pass x-points as an argument in the plot method. If the value of x-points is a sequential increment starting from 0 for example 1, 2, 3, .. and you just don't care about the values, you just need to only pass the y-points.


Default X-Points

Let's say that you want to plot the following points: (0, 1), (1, 5), (2, 10), (3, 8), (4, 11). You can do that by typing the following code

import matplotlib.pyplot as plt
import numpy as np

xpoints = np.array([0, 1, 2, 3, 4])
ypoints = np.array([1, 5, 10, 8, 11])

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

Which produces the following output

Plot 1

But notice that xpoints values are a sequential of 1 through 5 with the increment of 1 each step. In this case, you actually don't have to pass xpoints, therefore the code will look like this

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([1, 5, 10, 8, 11])

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

The output will be the same as the previous code output

Plot 2


There you go, that is how you can create a plot by only passing the y-points. Thank you for reading this article and have a great day!

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay