简体   繁体   English

matplotlib.pyplot.plot 只给了两个节点不给线,这是为什么呢?

[英]matplotlib.pyplot.plot just gives two nodes without giving the line, why is that?

I'm trying to draw a line between 2 nodes (x1=130, y1=130) and (x2=202, y2=202)我试图在 2 个节点 (x1=130, y1=130) 和 (x2=202, y2=202) 之间画一条线

this code works well此代码运行良好

coor = np.array([[130,202],[130,202]])
_ = plt.plot(coor[0],coor[1])

and I got我得到了

在此处输入图像描述

However, the following code coming from the matplotlib doc , does not work as stated there但是,来自matplotlib 文档的以下代码无法按此处所述工作

plt.plot(130, 130,'g^', 202, 202, 'r^')

在此处输入图像描述

which just gives two nodes without giving the line, why is that?它只给出了两个节点而没有给出线,这是为什么呢?

This is because in the matplotlib docs, in plot(x1, y1, 'g^', x2, y2, 'g-') , x1 , y1 , x2 and y2 are assumed to be different data sets , ie arrays consisting of multiple points.这是因为在 matplotlib 文档中,在plot(x1, y1, 'g^', x2, y2, 'g-') , x1 , y1 , x2y2被假定为不同的数据集,即 arrays点。

In this case, you'd get a plot of x1 vs y1 with green triangles and a green line connecting the points of x2 vs y2 .在这种情况下,您会得到x1y1的 plot 与绿色三角形和连接x2y2点的绿线。

But you won't have a line connecting x1:y1 to x2:y2 .但是您不会有一条线将x1:y1连接到x2:y2

Also you probably meant to write plt.plot(130, 130,'g^', 202, 202, 'r-') (note the minus instead of the ^ ).另外,您可能打算写plt.plot(130, 130,'g^', 202, 202, 'r-') (注意减号而不是^ )。

So eg this will work:所以例如这将起作用:

plt.plot([1, 2], [3, 4],'g^', [5, 6], [7, 8], '^-')

在此处输入图像描述

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

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