如何用 Tikz 创建三维概率树

如何用 Tikz 创建三维概率树

我想创建一个图表在此处输入图片描述如下所示。这个想法是九个节点落在同一个计划上,即同时。我在创建具有可变分支长度的树时遇到了一些问题。非常感谢。

我从给出下图的代码开始。

\documentclass{report}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usepackage{graphics}
\usetikzlibrary{trees}
\newenvironment{conditions}
{\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
    {\end{tabular}\par\vspace{\belowdisplayskip}}
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=2cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]




\begin{document}
\begin{figure}[!ht]
    \centering
    \begin{tikzpicture}
    [grow                    = right,
    sibling distance        = 6em,
    level distance          = 10em,
    edge from parent/.style = {draw, -latex},
    every node/.style       = {font=\footnotesize},
    sloped]
    \node[bag] {$r^{*}_{i, j}$}
    child {node[bag] {$r^{*}_{i+1, k_{3}}$}
        edge from parent [ - >] node[below]{$p_{d}$}
    }
    child {node[bag] {$r^{*}_{i+1, k_{2}}$}
        edge from parent [ - >] node[above]{$p_{m}$}
    }
    child {node[bag] {$r^{*}_{i+1, k_{1}}$}
        edge from parent [ - >] node[above]{$p_{u}$}
    };
    \end{tikzpicture}
    \caption{ The Branching Process of a Tree Element}
\end{figure}
\end{document}

在此处输入图片描述

答案1

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning, quotes, shapes.geometric}

\begin{document}
    \begin{tikzpicture}[
     node distance = 6mm and 22mm,
        dot/.style = {circle, fill=gray, node contents={}},
every label/.style = {inner sep=1pt, font=\footnotesize}
                        ]
\node (t) [trapezium,
           fill=gray!20, draw, dashed,
           minimum width=44mm, minimum height=11mm,
           rotate=-90] {};%shape border
\draw[dashed]   (t.north) -- (t.south)
                (t.west)  -- (t.east);
%
\node (r01)[dot,below left=of t.south,
            label=above left:{$r*_{i,j}$}];
%
\node (r11)[dot, at={(t.bottom left corner)},
            label=60:{$r^{*}_{i+1, k_{1}}$}];
\node (r12)[dot, at={(t.west)},
            label=60:{$r^{*}_{i+1, k_{2}}$}];
\node (r13)[dot, at={(t.top left corner)},
            label=60:{$r^{*}_{i+1, k_{3}}$}];
%
\node (r21)[dot, at={(t.south)}];
\node (r22)[dot, at={(t.center)}];
\node (r23)[dot, at={(t.north)}];
%
\node (r31)[dot, at={(t.bottom right corner)},
            label=-60:{$r^{*}_{i+1, k_{1}}$}];
\node (r32)[dot, at={(t.east)},
            label=-60:{$r^{*}_{i+1, k_{2}}$}];
\node (r33)[dot, at={(t.top right corner)},
            label=-60:{$r^{*}_{i+1, k_{3}}$}];
%

\draw[->]
    (r01) edge [sloped,"$p_{d}$"] (r11)
    (r01) edge [sloped,"$p_{m}$"] (r12)
    (r01) edge [sloped,"$p_{u}$"] (r13)
%
    (r01) edge [sloped] (r21)
    (r01) edge [sloped] (r22)
    (r01) edge [sloped] (r23)
%
    (r01) edge [sloped] (r31)
    (r01) edge [sloped] (r32)
    (r01) edge [sloped] (r33)
    ;
\node (r02)[dot, left =of r01];
\node (r03)[dot, below=of r01 |- r31];
\draw[->]
    (r02) edge  (r01)
    (r02) edge  (r03);
%
\coordinate[below=of r02 |- r03] (time-1);
\coordinate[below=of r33 |- r03] (time-2);
\draw[gray, very thick, ->]
    (time-1 -| r02.west) -- (time-2) node[below left] {time};
\draw[gray]
    (time-1)       +(0,1mm) -- ++ (0,-1mm) node[below] {$t$}
    (time-1 -| r31)+(0,1mm) -- ++ (0,-2mm) node[below] {$t_x$};
    \end{tikzpicture}

给出

在此处输入图片描述

相关内容