在NetworkX显示图中,节点位于精确(x,y)位置。结果被旋转 [英] in NetworkX show graph with nodes at exact (x,y) position. Result is rotated

查看:264
本文介绍了在NetworkX显示图中,节点位于精确(x,y)位置。结果被旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我从输入图像中提取一些角点并将角点保存为节点NetworkX中的图表。节点在检索角点时包含角点的(x,y)位置。然后显示将节点放置在其确切(x,y)位置的图形。但是,当我使用 nx.draw()显示图形时,该图显示了图片中的图形。



以下是您需要了解的一些代码:

  pe = nx.Graph()
pe .add_node('p1',posxy =(ap [0] [0],ap [0] [1]))
pe.add_node('p2',posxy =(ap [1] [0], ap'[2] [2]))
pe.add_node('p3',posxy =(ap [2] [0],ap [2] [3]))
pe.add_node(' p4',posxy =(ap [3] [0],ap [3] [4]))
pe.add_node('p5',posxy =(ap [4] [0],ap [4] [5]))
pe.add_cycle(['p1','p2','p3','p4','p5'])
positions = nx.get_node_attributes(pe,'posxy' )
nx.draw(pe,positions,node_size = 500)

其中 posxy =(ap [0] [0],ap [0] [1])是找到的角点平面中的位置。角点保存在列表中 ap



下面是检索到的形状图片: p>



,如图所示:



为什么输出结果一路显示?如何以类似于检测到的初始形状的方式旋转图形?

解决方案

您的NetworkX图是垂直反射你试图模仿的情节。为了解决这个问题,对于每个y坐标,使用 height - y ,其中 height 是你身材的高度。 p>

I am getting a trouble in showing my graph on networkX.

I extract some corner-points from a picture given in input and save the corner-points as node of a graph in NetworkX. The node contains the (x,y) positions of the corner-points as they are retrieved. I show then the graph placing the nodes at their exact (x,y) position. However, when I show the graph using nx.draw() the graph shows the shape retrieved in the picture all the way around.

Here is some code for you to understand:

pe = nx.Graph()
pe.add_node('p1', posxy=(ap[0][0], ap[0][1]))
pe.add_node('p2', posxy=(ap[1][0], ap[1][2]))
pe.add_node('p3', posxy=(ap[2][0], ap[2][3]))
pe.add_node('p4', posxy=(ap[3][0], ap[3][4]))
pe.add_node('p5', posxy=(ap[4][0], ap[4][5]))
pe.add_cycle(['p1','p2','p3','p4','p5'])
positions = nx.get_node_attributes(pe,'posxy')
nx.draw(pe, positions, node_size=500)

where posxy=(ap[0][0], ap[0][1]) is the position in the plane of the found corner-point. The corner-points are saved in a list ap.

Here is the picture of the shape retrieved:

and this the shown graph:

Why is the output shown all the way aroud? How can I rotate the graph in a way that resembles the initial shape detected?

解决方案

Your NetworkX plot is a vertical reflection of the plot you are trying to mimic. To fix this, for each y coordinate, use height - y where height is the height of your figure.

这篇关于在NetworkX显示图中,节点位于精确(x,y)位置。结果被旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆