简体   繁体   中英

What does the third parameter of plt.plot() in matplotlib do?

plt.plot() usually accepts x,y and format. But if I pass third argument as data another line is plotted. I can't understand the relationship.

x=np.linspace(0,10,5)
plt.plot(x,x,x,label='linear')
plt.grid()

Created plot:在此处找到上述代码的输出

This page of the docs outlines the call signatures for matplotlib.pyplot.plt() . Specifically relevant here is the signature

plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)

And the parameter description

x, y : array-like or scalar

The horizontal and vertical components of the data points. x values are optional and default to range(len(y)) .

When you do something like

plt.plot(x,x,x)

You are actually specifying a first set of x values followed by the corresponding y values and then a second set of y values which are paired with the default x values of range(len(y)) and plotted, resulting in two lines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM