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()
Which produces the following output
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()
The output will be the same as the previous code output
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!
Top comments (0)