使 VertexRenderingFunction 达到(不)缩放 [英] Getting VertexRenderingFunction to (not) scale

查看:18
本文介绍了使 VertexRenderingFunction 达到(不)缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义 VertexRenderingFunction 时遇到问题,显示不同图形的不同大小.下面是一个示例,默认的顶点渲染函数具有所需的行为,因为所有图中的顶点看起来都相同,有什么建议如何使用自定义顶点实现这一点吗?


(来源:
(来源:值.

Inset 也可以/代替在其第四个参数中采用大小,但默认设置遵循 inset Graphics 对象的 ImageSize,在这种情况下使用起来更简洁.

希望有帮助!

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?


(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];

Update, 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


(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]

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!

这篇关于使 VertexRenderingFunction 达到(不)缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆