2
$\begingroup$

I am trying to use Graph (not GraphPlot) and replace some of the vertices with an image, like so:

Graph[
 graph,
 EdgeWeight -> edges,
 EdgeLabels -> "EdgeWeight",
 VertexLabels -> "Name",
 VertexShapeFunction -> {_?(KeyExistsQ[sprites, #] &) -> 
    SpriteVertexFunction}
 ]

I define SpriteVertexFunctions without really using any of the callback parameters:

SpriteVertexFunction[{xc_, yc_}, name_, {w_, h_}] := sprites[name];

And sprites is an Association of numbers to imported images, which I've tried Rasterizeing too:

enter image description here

The error I'm getting is

Graphics is not a Graphics primitive or directive.

Can Graph not draw verticies with arbitrary images? Do I have to use GraphPlot instead?

$\endgroup$
1
  • $\begingroup$ Use Inset[] with VertexShapeFunction. $\endgroup$ Jun 4, 2016 at 4:36

1 Answer 1

4
$\begingroup$

You could use Property, e.g.

sims = MapIndexed[Property[#2[[1]], VertexShape -> #1] &, simpsons]
g = {1 -> 2, 2 -> 4, 2 -> 5, 2 -> 6, 3 -> 4, 3 -> 5, 3 -> 6};
Graph[sims, g, VertexSize -> 0.6]

I am posting image of code to see effect:

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ D'oh! (+1)$\phantom{}$ $\endgroup$ Jun 4, 2016 at 9:09

Your Answer

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

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