开发者

Getting VertexRenderingFunction to (not) scale

开发者 https://www.devze.com 2023-01-24 03:29 出处:网络
I\'m having problem with custom VertexRenderingFunction showing at different sizes for different graphs. An example is below, the default vertex rendering function has the desired behavior since verti

I'm having problem with custom VertexRenderingFunction showing at different sizes for different graphs. An example is below, the default vertex rendering function has the desired behavior since vertices look the same in all graphs, any suggestion how to achieve that with custom vertices?

Getting VertexRenderingFunction to (not) scale

(source: yaroslavvb.com)

edges = Most[
    ArrayRules[GraphData[{"Path", 5}, "AdjacencyMatrix"]]][[All, 1]];
doit[vrf_] := 
  Print /@ Table[
    GraphPlot[Rule @@@ edges[[k ;;]], VertexRenderingFunction -> vrf, 
     VertexLabeling -> True], {k, 1, Length[edges]}];
doit[({White, EdgeForm[Black], Disk[#, .1], Black, Text[#2, #1]} &)];
doit[Automatic];

U开发者_高级运维pdate, 1 hour later:

Michael Pilat as usual gives the solution, here's what it looks like with

(Inset[Graphics[{White, EdgeForm[Black], Disk[{0, 0}, .05], Black, 
     Text[#2, {0, 0}]}, ImageSize -> 25], #] &) 
for rendering function

Getting VertexRenderingFunction to (not) scale

(source: yaroslavvb.com)


Inset a Graphics expression with the ImageSize option to place your vertices:

GraphPlot[Rule @@@ edges,
 VertexRenderingFunction -> (Inset[
     Graphics[{White, EdgeForm[Black], Disk[{0, 0}, .05], Black, 
       Text[#2, {0, 0}]}, ImageSize -> 25], #] &),
 VertexLabeling -> True]

Getting VertexRenderingFunction to (not) scale

ImageSize can take a variety of values from printer's points to a Scaled value.

Inset can also/instead take a size in its fourth argument, but the default setting defers to the ImageSize of the inset Graphics object, which is a little cleaner to use in this case.

Hope that helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消