简体   繁体   中英

NetworkX plotting: different units/scale between node positions and sizes?

I'm working on a graph with (x,y) node coordinates randomly picked from 0-100. If I simply plot the graph using nx.draw() and passing the original coordinates it looks ok, but if I try to plot some node sizes in a way it relates to coordinates it looks clearly inconsistent.

Looks like the nodes position parameter in draw() is not in the same unit of the node sizes, which are in pixels.Sadly there's nothing about position units in NetworkX documentation...

Ok, I figured it out...

Position parameter for nodes are relative, from 0.0 to 1.0 times whatever your plot size is, while size parameter is absolute, in pixels

Networkx uses matplotlib to plot things. It does not use pixels for its coordinates, and for good reason.

If you you have coordinates whose values range from -0.01 to 0.01, it will produce a plot that scales the upper and lower bounds on the coordinates to be large enough to hold this, but not so large that everything is in a tiny little bit of the plot. If you now add points with coordinate values around 100, it will rescale the plot to show these as well.

Think about how it would look to plot the line y = x+1 for x in (-0.5, 0.5) if matplotlib insisted that 1 had to correspond to a pixel.

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