1
$\begingroup$

An arbitrary example:

Create a random image

Image[RandomReal[{0, 1}, {10, 10}], ImageSize -> Medium]

enter image description here

Define some points and a graph to align

c = PixelValuePositions[%, White, .1]
RandomGraph[Table[Length[c], 2]]

enter image description here

Out[1]: {{2, 9}, {1, 8}, {1, 7}, {2, 7}, {9, 6}, {2, 2}}

How can I align the nodes of a graph to coordinates on an image?

Ideally this would be a graph from a correlation matrix

RandomReal[{-1, 1}, Table[Length[c], 2]] // MatrixForm

$\endgroup$
2
$\begingroup$
SeedRandom[1]
img = Image[RandomReal[{0, 1}, {10, 10}], ImageSize -> Medium];
c = PixelValuePositions[img, White, .1];

rg = RandomGraph[Table[Length[c], 2], ImageSize -> Medium];

rg2 = SetProperty[rg, 
   {VertexCoordinates -> c - 1/2, EdgeStyle -> Directive[Red, Thick]}];

Row[{rg, Show[img, rg2]}]

enter image description here

$\endgroup$
2
  • $\begingroup$ How can I remove the self lines from a WeightedAdjacencyGraph[] of a correlation matrix? it seems the removal in the help is done by setting to infinite but this seems there may be a setting I can not see $\endgroup$
    – Teabelly
    Mar 31 '21 at 15:00
  • $\begingroup$ @Teabelly, replacing 0's with Infinitys is the only way I know. $\endgroup$
    – kglr
    Mar 31 '21 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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