树的分支中的概率

树的分支中的概率

我有以下树,但我想在树枝上放一些概率。有人能帮我吗?

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{tikz}
\usepackage{forest}% for version 1
\tikzset{darkp/.style={fill=purple!50!black},
        lightp/.style={fill=purple!50}}
        
\begin{document}
\begin{forest}
  for tree={
    grow'=0,
    draw,
    align=c,
    font=\sffamily,
    fill=purple,
    text=white,
    edge=purple,
    parent anchor=east,
    child anchor=west,
    edge path={%
      \noexpand\path [\forestoption{edge}] (!u.parent anchor) -- ++(5pt,0) |- (.child anchor)\forestoption{edge label};
    }
  },
  highlight/.style={
    thick,
    font=\sffamily\bfseries
  }
   [[{Nebulosa rouba a joia}
  [{Thanos fica sem a joia}, lightp]
  ]
  [{Peter Quill \\ rouba a joia}
        [{Kree captura Quill}
        [{Quill foge sem a joia}]
       [{Quill foge com a joia}
         [{Luta com Ronan}
         [{Vence}
         [{Joia é entregue a Tropa Nova}
         [{Thanos consegue a joia}
         [{Thanos fica com a joia} , darkp]
         ]
         ]
         [{Quill fica com a joia}
         [{Thanos vence}
         [{Thanos fica com a joia},darkp]
         ]
         [{Quill vence}
         [{Thanos fica sem a joia},lightp]
         ]
         ]
         [{Quill entrega a joia para Youndu}
         [{Youndu vence}
         [{Thanos fica sem a joia},lightp]
         ]
         [{Thanos vence}
         [{Thanos fica com a joia},darkp]
         ]
         ]
         ]
         ]
         [{Perde}
         [{Thanos fica sem a joia},lightp]
         ]
         ]
         [{Quill vende a joia}
         [{Thanos fica sem a joia},lightp]
         ]
         ]
         ]
    [{Quill escapa}
      [{Quill fica com a joia}
      [{Quill vende a joia}
      [{Thanos fica sem a joia}, lightp]
      ]
      [{Quill vence}]
      [{Thanos vence}
      [{Thanos fica com a joia},darkp]
      ]
      ]
      ]
        ]
      ]
        ]
    ]
  ]
\end{forest}
\begin{tikzpicture}[remember picture,overlay]
    \node[draw,rounded corners=5pt,fill=purple,text=white,font=\sffamily,inner sep=6pt] at (10,8) {Another Event};
\end{tikzpicture}
\end{document}

答案1

抱歉,您的问题不太清楚。您的图表与决策树没有关联(在我看来),那么您希望在哪里(哪个分支)放置带有概率值的标签?标签应该如何放置?

因此,这里展示的解决方案仅可作为起点。它具有:

  • 改进的图表代码(与问题中显示的代码相比)
  • 在一些分支上添加了标签,仅显示如何在其他分支上自己执行此操作
\documentclass[border=3mm]{standalone}
\usepackage[edges]{forest}% for forked tree

\begin{document}
\begin{forest}
  for tree = {
    draw,
    font=\sffamily,
    fill=purple,
  darkp/.style = {fill=purple!60!black},
 lightp/.style = {fill=purple!50},
    text=white,
    minimum height=5ex,
    text width=5.4em, text badly centered, 
%
    grow'=0,
    forked edge,        
    s sep = 4mm,        
    l sep = 12mm,        
 fork sep = 4mm,       
          anchor = east,
    child anchor = west,
% edge laels
/tikz/ELS/.style = {% Edge Label Style
                    pos=0.75, sloped,
                    fill=white, font=\small, text=black, inner sep=2pt},
EL/.style = {edge label={node[ELS]{$#1$}}},
%       
     edge = purple,
             }
[, coordinate
    [Nebulosa rouba a joia, EL=p_1 % <---
        [Thanos fica sem a joia, lightp]
    ]
    [Peter Quill rouba a joia, EL=p_2 % <---
        [Kree captura Quill
            [Quill foge sem a joia, EL=q_1]% <---
            [Quill foge com a joia, EL=q_2, % <--- 
             before computing xy={s/.average={s}{siblings}}
                [Luta com Ronan
                    [Vence
                        [Joia é entregue a Tropa Nova
                            [Thanos consegue a joia
                                [Thanos fica com a joia, darkp]
                            ]
                        ]
                        [Quill fica com a joia,
                         before computing xy={s/.average={s}{siblings}}
                            [Thanos vence
                                [Thanos fica com a joia,darkp]
                            ]
                            [Quill vence
                                [Thanos fica sem a joia,lightp]
                            ]
                        ]
                        [Quill entrega a joia para Youndu
                            [Youndu vence
                                [Thanos fica sem a joia,lightp]
                            ]
                            [Thanos vence
                                [Thanos fica com a joia,darkp]
                            ]
                        ]
                    ]
                ]
                [Perde
                    [Thanos fica sem a joia,lightp]
                ]
            ]
            [Quill vende a joia, EL=q_3, % <--- 
                [Thanos fica sem a joia,lightp]
            ]
         ]
    ]
    [Quill escapa, EL=p_3 % <---
        [Quill fica com a joia
            [Quill vende a joia
                [Thanos fica sem a joia, lightp]
            ]
            [Quill vence,
             before computing xy={s/.average={s}{siblings}}]
            [Thanos vence
                [Thanos fica com a joia,darkp]
            ]
        ]   
    ]
]
\end{forest}
\end{document}

在此处输入图片描述

笔记:第二幅图(绘制为 Ti我使用了一个与 Z 图片相关的示例,但由于其目的不明确(至少对我来说),所以它被删除了。

相关内容