1
$\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$
3
$\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$

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.