joey lang
joey lang

Reputation: 187

How does matplotlib.pyplot.plot function work with only one parameter?

The matplotlib.pyplot.plot documentation says that- plot(y) # plot y using x as index array 0..N-1

So what would be the output with y=[1,2,3,4,5,6,7,8,9,10] ans with y=[2,4,6,8,10]? I plotted them but was not able to infer anything. Please Help

Upvotes: 1

Views: 1442

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339765

You can assume that plt.plot(y) is equivalent to plt.plot(range(len(y)), y). Meaning, the first entry in y is plotted at x=0, the second at x=1, etc until the last, at x=N-1 (where N=len(y)).

This means in the case y=[1,2,3,4,5,6,7,8,9,10], you plot

x = [0,1,2,3,4,5,6,7,8,9]
y = [1,2,3,4,5,6,7,8,9,10]
plt.plot(x,y)

In the case of y=[2,4,6,8,10], it'll be

x = [0,1,2,3,4]
y = [2,4,6,8,10]
plt.plot(x,y)

Upvotes: 5

Related Questions