无重叠的树形
我有时会遇到 TreeForm 中的标签由于重叠而无法读取的问题。下面是一个例子,有人能找到消除重叠的方法吗?
{{4, 5, 6}, {{{2, 4, 5, 6}, {{{1, 2, 4}, {}}, {{2, 3, 6}, {}}}}, {{4, 5, 6, 8}, {{{4, 7, 8}, {}}, {{6, 8, 9}, {}}}}}} // TreeForm
(来源:yaroslavvb.com)
贝利撒留的解决方案有助于解决重叠问题,但丢失工具提示,即与
TreeForm[Hold[ GraphPlotHighlight[edges : {((_ -> _) | {_ -> _, _}) ...}, hl : {___} : {}, opts : OptionsPattern[]] := Module[{verts, coords, g, sub}, 5]]]
(来源:yaroslavvb.com)
答案11/12 更新 我最终使用了下面的代码(贝利萨留的代码进行了一些小修复)
myTreeForm[exp_] :=
Module[{tooltipText, i},
tooltipText =
Cases[Cases[MakeBoxes[TreeForm@exp, StandardForm],
TooltipBox[x__] -> x, 7, Heads -> True],
TagBox[x__, y__] -> DisplayForm[First@{x}], Heads -> True];
i = 0;
TreeForm[exp,
VertexRenderingFunction -> ({Tooltip[
Inset[Rasterize[Text[" " <> ToString@#2 <> " "],
Background -> LightBlue], #1], tooltipText[[i++]]]} &)]];
I sometimes run into the problem of labels in TreeForm being unreadable because of overlap. An example is below, can anyone see a way to get rid of overlap?
{{4, 5, 6}, {{{2, 4, 5, 6}, {{{1, 2, 4}, {}}, {{2, 3, 6}, {}}}}, {{4, 5, 6, 8}, {{{4, 7, 8}, {}}, {{6, 8, 9}, {}}}}}} // TreeForm
(source: yaroslavvb.com)
Belisarius' solution helps with overlap, but loses Tooltips, ie compare with
TreeForm[Hold[ GraphPlotHighlight[edges : {((_ -> _) | {_ -> _, _}) ...}, hl : {___} : {}, opts : OptionsPattern[]] := Module[{verts, coords, g, sub}, 5]]]
(source: yaroslavvb.com)
Answer update 11/12
I ended up using code below (belisarius' code with a minor fix)
myTreeForm[exp_] :=
Module[{tooltipText, i},
tooltipText =
Cases[Cases[MakeBoxes[TreeForm@exp, StandardForm],
TooltipBox[x__] -> x, 7, Heads -> True],
TagBox[x__, y__] -> DisplayForm[First@{x}], Heads -> True];
i = 0;
TreeForm[exp,
VertexRenderingFunction -> ({Tooltip[
Inset[Rasterize[Text[" " <> ToString@#2 <> " "],
Background -> LightBlue], #1], tooltipText[[i++]]]} &)]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前也这样做过,但从未概括过结果。
编辑 使用工具提示
使用“不同的方法”
代码很脏,抱歉没有时间立即清理它
输出
编辑 2
我认为这个版本更好:
输出:
编辑 4 ...和最后一个
清理代码,删除虚假函数和变量那只是让事情变得复杂:
HTH!
I did this before, but never generalized the result.
Edit With Tooltips
Using a "different approach"
Code is dirty, sorry no time to clean it up right now
Output
Edit 2
I think this version is better:
Output:
Edit 4 ... and last one
Cleaned up code, remove spurious functions and variables that were there just to complicate things:
HTH!
看来选项
VertexCooperativeRules
可能是您最好的希望。It looks as if the option
VertexCoordinateRules
may be your best hope.