7
$\begingroup$

Bug introduced in 10.3 or earlier and fixed in 13.1


When all the points are the same kind, say Integer then NearestNeighborGraph will display a 3D graph when using {x,y,z} coordinates. However, when just one of those points is say a Decimal instead then one sees a 2D graph. It seems the reverse is true too. For example:

allIntegers = NearestNeighborGraph[{{0,0,0},{-1,1,1},{1,-1,1},{-1,-1,1},{1,1,1},{0,0,2},{0,0,1}},{All,2}];
allDecimals = NearestNeighborGraph[{{0.,0.,0.},{-1.,1.,1.},{1.,-1.,1.},{-1.,-1.,1.},{1.,1.,1.},{0.,0.,2.},{0.,0.,1.}},{All,2}];

oneInteger = NearestNeighborGraph[{{0,0.,0.},{-1.,1.,1.},{1.,-1.,1.},{-1.,-1.,1.},{1.,1.,1.},{0.,0.,2.},{0.,0.,1.}},{All,2}];
oneDecimal = NearestNeighborGraph[{{0.,0,0},{-1,1,1},{1,-1,1},{-1,-1,1},{1,1,1},{0,0,2},{0,0,1}},{All,2}];

Row[{allIntegers, allDecimals, oneInteger, oneDecimal}]

Displays:

2 3D graphs and 2 2D graphs

Is there something I'm doing wrong or some parameter I need to pass? I'd like to be able to force 3D.

$\endgroup$
4
  • $\begingroup$ I would call this a bug. Please report it to Wolfram. Note that this is not an official Wolfram website, so the issue won't come to their attention unless you report it. $\endgroup$
    – Szabolcs
    Commented Nov 12, 2020 at 10:24
  • 2
    $\begingroup$ Bug reported, lets see what happens. $\endgroup$ Commented Nov 12, 2020 at 10:39
  • 1
    $\begingroup$ I received an email on the 13th of September 2022 to say it's now been fixed. I've tested it in 13.1 and all test cases above return 3D Graphs as expected. $\endgroup$ Commented Oct 29, 2022 at 5:08
  • $\begingroup$ In similar cases, feel free to edit the bug header. I'll do it this time. $\endgroup$
    – Szabolcs
    Commented Oct 29, 2022 at 16:02

1 Answer 1

5
$\begingroup$

One possible workaround to this bug is to set VertexCoordinates explicitly.

pts = {{0., 0, 0}, {-1, 1, 1}, {1, -1, 1}, {-1, -1, 1}, {1, 1, 1}, {0, 0, 2}, {0, 0, 1}};

NearestNeighborGraph[pts, {All, 2}, 
   VertexCoordinates -> pts (* <-- workaround *)]
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.