gpt4 book ai didi

wolfram-mathematica - 数学 : How do I make a partial binary tree appear binary?

转载 作者:行者123 更新时间:2023-12-04 08:01:33 29 4
gpt4 key购买 nike

在最近 SO discussion我展示了一个需要修剪顶点 6 和 7 的二叉分类树:

needs pruning

下面是我使用的代码:

KaryTree[9, 2, 
VertexLabels -> {1 -> "Blood pressure > 91 ?", 2 -> "Age > 62.5?",
4 -> "Sinus tachycardia ?", 8 -> "< 30 days"},
EdgeLabels -> {1 \[UndirectedEdge] 2 -> "yes",
1 \[UndirectedEdge] 3 -> "no", 2 \[UndirectedEdge] 4 -> "yes",
2 \[UndirectedEdge] 5 -> "no", 4 \[UndirectedEdge] 8 -> "yes",
4 \[UndirectedEdge] 9 -> "no"}, ImagePadding -> 20]

如果叶子 6 和 7 被 VertexDelete 修剪,顶点 8 和 9 也被裁剪:
VertexDelete[
KaryTree[7, 2,
VertexLabels -> {1 -> "Blood pressure > 91 ?", 2 -> "Age > 62.5?",
4 -> "Has sinus tachycardia ?"},
EdgeLabels -> {1 \[UndirectedEdge] 2 -> "yes",
1 \[UndirectedEdge] 3 -> "no", 2 \[UndirectedEdge] 4 -> "yes",
2 \[UndirectedEdge] 5 -> "no"}, ImagePadding -> 20], {6, 7}]

VertexDelete

TreeGraph 愿意绘制图形,但它对图形的布局有自己的想法:
TreeGraph[{1 \[UndirectedEdge] 2, 1 \[UndirectedEdge] 3, 
2 \[UndirectedEdge] 4, 2 \[UndirectedEdge] 5, 4 \[UndirectedEdge] 6,
4 \[UndirectedEdge] 7},
VertexLabels -> {1 -> "Blood pressure > 91 ?", 2 -> "Age > 62.5?",
4 -> "Has sinus tachycardia ?", 6 -> "< 30 days"},
EdgeLabels -> {1 \[UndirectedEdge] 2 -> "yes",
1 \[UndirectedEdge] 3 -> "no", 2 \[UndirectedEdge] 4 -> "yes",
2 \[UndirectedEdge] 5 -> "no", 4 \[UndirectedEdge] 6 -> "yes",
4 \[UndirectedEdge] 7 -> "no"}, ImagePadding -> 20]

TreeGraph

我希望顶点 1 作为图形的根显示在顶部。

我玩过各种 GraphLayout设置但没有找到解决方案。有任何想法吗?

最佳答案

也许你可以使用:

vertex = {1 -> "Blood pressure > 91 ?",   2 -> "Age > 62.5?", 
4 -> "Has sinus tachycardia ?", 6 -> "< 30 days"};

TreePlot[{{1 -> 2, yes}, {1 -> 3, no}, {2 -> 4, yes},
{2 -> 5, no}, {4 -> 6, yes}, {4 -> 7, no}} /. vertex, Top,
1 /. vertex, VertexLabeling -> True]

enter image description here

编辑

或者,如果您想要更好的模拟:
gr = Graphics[
List[Hue[0.6`, 0.2`, 0.8`], EdgeForm[Opacity[0.7`]],
Disk[List[2.5021729686848975, 1.6681153124565984], 0.02965727689850835]],
Rule[ImageSize, List[13.`, Automatic]]] ;

vertex = {1 -> "Blood pressure > 91 ?", 2 -> "Age > 62.5?",
4 -> "Has sinus tachycardia ?", 6 -> "< 30 days",
3 -> "", 5 -> " ", 7 -> " "};

TreePlot[{{1 -> 2, yes}, {1 -> 3, no }, {2 -> 4, yes},
{2 -> 5, no}, {4 -> 6, yes}, {4 -> 7, no}}/. vertex, Top, 1/. vertex,
VertexLabeling -> True,
PlotStyle -> Hue[0.6`, 0.7`, 0.5`],
VertexRenderingFunction -> ({Inset[gr, #1], Inset[#2, #1, {-1.3, -1}]} &)]

enter image description here

关于wolfram-mathematica - 数学 : How do I make a partial binary tree appear binary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6582187/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com