简体   繁体   English

matplotlib 中 plt.plot() 的第三个参数有什么作用?

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

plt.plot() usually accepts x,y and format. plt.plot()通常接受 x、y 和格式。 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() . 文档页面概述了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 x, y : 类似数组或标量

The horizontal and vertical components of the data points.数据点的水平和垂直分量。 x values are optional and default to range(len(y)) . x值是可选的,默认为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.您实际上是在指定第一组x值,然后是相应的y值,然后是第二组y值,这些值与range(len(y))的默认x值配对并绘制,从而产生两条线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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