4

I am trying to use GraphPlot function to build a Graph, where each node is an image. I wanted to display the image as my vertex. Does anybody know how to do this?

I tried something like this:

GraphPlot[  Map[If[# > 2.0 , 0, 1] &,
 imgDistT, {2}],  
 VertexRenderingFunction -> (Inset[imgs[[#2]], #1, Center] &) ]

But this does not work. imgs is my list of images corresponding to each vertex number.

As a sanity check, if i do this:

GraphPlot[
 Map[If[# > 2.0 , 0, 1] &, imgDistT, {2}], 
 VertexRenderingFunction -> (Inset[Text[#2], #1, Center] &) ]

then that works and it shows me the vertex number at each node.

2 Answers 2

4
 imgs = ExampleData /@ ExampleData["TestImage"];
 GraphPlot[{1 -> 4, 1 -> 5, 2 -> 3, 2 -> 4, 2 -> 5, 3 -> 4, 3 -> 5}, 
   VertexRenderingFunction -> (Inset[Image[imgs[[#2]], ImageSize -> 100], #1] &)]

enter image description here

Edit

-- Infix notation joke removed --

Sign up to request clarification or add additional context in comments.

5 Comments

I honestly do not understand the obsession with infix. It's now more of an in joke than anything else :P
@yoda Yep. I will end my infix posts here. I just consider the ~ notation confusing and I use it sparsely and only for operators spelled that way (like a PLUS b, a OR b, etc) or those like JOIN with very easy to understand meanings. Mathematica programs are usually difficult to follow without any added complexity.
@yoda et al, for some while I used infix notation in my own code, but generally refrained from posting it here. However, in a few cases were I left it in, I received several "+1 for the infix notation" type comments, so I started posting it. It is my intention, within reason, to format the code I post as the community finds valuable. Indeed this has become a joke, rather at my expense now. I have not and will not post code resembling the line above, nor would I write such a tangle, as I am sure belisarius knows. If code I post is hard to read, tell me.
@Mr. Please don't take it personally. It is just a joke. And if something is true behind it, as it is with many jokes, is that for some people the extensive use of infix notation is harder to read. Please continue posting as you feel more comfortable. Although I have been joking around about it a little, that does not mean any disrespect. I am here to learn a bit and have some fun. That is it.
@belisarius I do not take it personally, and I didn't mean to suggest I was personally attacked. I enjoy your humor, even if at times I don't get it. Please feel free to keep a light attitude. :-) I guess my issue is that I feel my position is being misrepresented. Specifically: I don't try to shoe-horn infix form into everything, and I started with the assumption that since it is used rarely, it would be harder for many to read. I started posting more of it when I received positive comments, and now that I have received negative ones, I shall post it less.
2

Two possible issues:

  • It looks like your graph, Map[If[# > 2.0 , 0, 1] &, imgDistT, {2}], will contain zeroes and ones—but zeroes are invalid indices for the imgs array

  • The images may not appear properly due to scaling issues—for example, they might be really big only the white portion might be visible. Try specifying an explicit image size.

What is the output of

GraphPlot[Map[If[# > 2.0 , 0, 1] &, imgDistT, {2}],
 VertexRenderingFunction -> (Module[{tmp = 
       Inset[Image[imgs[[#2]], ImageSize -> 10], #1, Center]}, 
     Print[tmp]; tmp] &)]

?

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.