寻找如何在 TikZ 中绘制该图表

寻找如何在 TikZ 中绘制该图表

我希望在 Ti 中创建类似的东西Z 环境。我对它们之间的关系有点困惑:当不确定是否会使用所有块时,将一个块定位在另一个块之下似乎很奇怪。另外,我不知道如何获取这些“列”。

在此处输入图片描述


编辑

这是迄今为止我尝试过的代码。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}

\colorlet{mygreen}{green!80!black}
\colorlet{myblue}{blue!80!black}
\colorlet{myred}{red!80!black}

\begin{document}

\begin{tikzpicture}[
std/.style={
  draw,text width=2.5cm,align=center, font=\strut\sffamily
  },
rnd/.style={ draw=#1,rounded corners=8pt,line width=1pt,
  align=center, text width=3cm,minimum height=2cm,
  font=\strut\sffamily
  },
vac/.style={
  text width=2.5cm,align=center, font=\strut\sffamily
  },
ar/.style={
 ->,>=latex
  },
node distance=0.5cm and 3cm    
]
%The nodes for the left
\node[vac](urs) {\textbf{Ursache}};
\node[std,below=1cm of urs] (va) {Zeit};
\node[std,below=of va] (fs) {Formierung};
\node[std,below=of fs] (vs) {Vehicle Speed};
\node[std,below=of vs] (cv){Cabin Volume};
\node[std,below= 1cm of cv] (fr) {Fraction of Recirculation};
\node[std,below=of fr] (ac) {Ambient $CO_{2}$ Concentration};
\node[std,below=of ac] (op) {Occupant Parameters};

%The nodes for the center
\node[vac, right= of urs](dm) {degradation mech};
\node[std,right=of va,yshift=-12.5pt,fill=pink] (aer) {SEI- Wachstum};
\node[std,below=of aer,fill={rgb:red,4;green,2;yellow,1}] (cdm){Carbon Dioxide Built-in Module};
\node[std,below=of cdm] (vcm){Vehicle Cabin Module};
\node[std,below=of vcm] (hvac){HVAC Module};

%The nodes for the right

\node[std,right= of cdm,fill=green] (occ) {Verlust Lithium};
\node[std,right= of vcm,fill=yellow] (the) {Thermal Environment};
\node[vac,right= of hvac,fill=orange] (col){Compressor Load};

\draw[blue] (va)  to (aer);
\draw[red] (aer.east) to (occ.west);
\draw (fs) to (aer.west);\draw (fs) to (cdm.west);
\draw (cv.east) to (aer.west);
\draw (vs.east) to (cdm.west);
;

%The dashed fitting node
\node[draw,dashed,inner sep=8pt,fit={(urs) (op)}]
  (fit) {};
\node[draw,dashed,inner sep=8pt,fit={(dm) (hvac)}]
  (fit) {};
  \node[draw,dashed,inner sep=8pt,fit={(occ) (col)}]
  (fit) {};

\end{tikzpicture}

\end{document}

我的代码创建了下图,但距离我想要实现的结果还很远。

在此处输入图片描述

答案1

该解决方案创建了一个tikzset命名myBlock,以紧凑地定义所有指令,以您想要的样式在节点周围绘制矩形。

该语法[below=<value> of <node>]负责确保每个节点都恰好位于另一个给定节点下方。

我使用循环来压缩每个节点的foreach连接方式。我根据箭头的颜色将其分为四组:redred!50和。您也可以定义新颜色或将颜色插入为每个箭头的参数。我发现定义整个集合的颜色很简单,主要是因为我可以重新定义整个集合的属性,而不是单独进行定义。blueblue!50

请修改颜色和连接。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{myBlock/.style n args={2}{
    every node/.style={rectangle,fill, text=black, minimum width=#1, minimum height=#2,}
    },
    myBlock/.default={5cm}{1cm}
 }
\begin{document}
\begin{tikzpicture}
  
  \fill[gray,opacity=0.2] (0,0)
  node[below right,black,text opacity=1]{Cause} rectangle ++(5,-18);
  \fill[gray,opacity=0.2] (7,0)
  node[below right,black,text opacity=1]{Degradation Mechanism} rectangle ++(5,-18);
  \fill[gray,opacity=0.2] (14,0)
  node[below right,black,text opacity=1]{Degradation Mode} rectangle ++(5,-18);
  \fill[gray,opacity=0.2] (21,0)
  node[below right,black,text opacity=1]{Effect} rectangle ++(5,-18);
  
  \begin{scope}[myBlock]
    \node[fill=red,text=white] at (2.5,-2) (A1) {Time};
    \node[fill=red!90,text=white] [below=1 of A1] (A2) {High temperature};
    \node[fill=red!80,text=white] [below=1 of A2] (A3) {A3};
    \node[fill=red!70] [below=1 of A3] (A4) {A4};
    \node[fill=blue!70] [below=1 of A4] (A5) {A5};
    \node[fill=blue!80,text=white] [below=1 of A5] (A6) {A6};
    \node[fill=blue!90,text=white] [below=1 of A6] (A7) {A7};
    \node[fill=blue,text=white] [below=1 of A7] (A8) {A8};
  \end{scope}
  
  \begin{scope}[shift={(7,0)},myBlock]
    \node[fill=red,text=white] at (2.5,-2) (B1) {SEI growt};
    \node[fill=red!90,text=white] [below=0.5 of B1] (B2) {SEI decomposition};
    \node[fill=red!80,text=white] [below=0.5 of B2] (B3) {B3};
    \node[fill=red!70] [below=0.5 of B3] (B4) {B4};
    \node[fill=red!60] [below=0.5 of B4] (B5) {B5};
    \node[fill=blue!50,text=white] [below=0.5 of B5] (B6) {B6};
    \node[fill=blue!60,text=white] [below=0.5 of B6] (B7) {B7};
    \node[fill=blue!70,text=white] [below=0.5 of B7] (B8) {B8};
    \node[fill=blue!80,text=white] [below=0.5 of B8] (B9) {B9};
    \node[fill=blue!90,text=white] [below=0.5 of B9] (B10) {B10};
    \node[fill=blue,text=white] [below=0.5 of B10] (B11) {B11};
  \end{scope}
  
  \begin{scope}[shift={(14,0)},myBlock]
    \node[fill=red,text=white] at (2.5,-4) (C1) {Loss of lithium inventory};
    \node[fill=blue!50] [below=3 of C1] (C2) {C2};
    \node[fill=blue,text=white] [below=3 of C2] (C3) {C3};
  \end{scope}
  
  \begin{scope}[shift={(21,0)},myBlock]
    \node[fill=red,text=white] at (2.5,-5) (D1) {Capacity fade};
    \node[fill=blue!50,text=white] [below=4 of D1] (D2) {D2};
  \end{scope}
  
  \begin{scope}[very thick, red]
    \draw (A1.east) -- (B1.west);
    \foreach \n in {1,2,3,4}{
      \draw (A2.east) -- (B\n.west);
    }
    \foreach \n in {1,2,...,5}{
      \draw (A3.east) -- (B\n.west);
    }
    
    \foreach \n in {1,2,3,7}{
      \draw (B\n.east) -- (C1.west);
    }
  \end{scope}
  
  \begin{scope}[very thick, red!50]
    \foreach \n in {1,2,5,6,8,9}{
      \draw (A4.east) -- (B\n.west);
    }
    \foreach \n in {1,2,3}{
      \draw (C\n.east) -- (D1.west);
    }
  \end{scope}
  
  \begin{scope}[very thick, blue]
    \foreach \n in {8,9}{
      \draw (A7.east) -- (B\n.west);
    }
    \foreach \n in {7,8,10,11}{
      \draw (A8.east) -- (B\n.west);
    }
    \foreach \n in {4,6,8,9,10,11}{
      \draw (B\n.east) -- (C3.west);
    }
  \end{scope}
  
  \begin{scope}[very thick, blue!50]
    \draw (A5.east) -- (B7.west);
    \foreach \n in {7,10}{
      \draw (A6.east) -- (B\n.west);
    }
    \foreach \n in {4,5,7,8,9,11}{
      \draw (B\n.east) -- (C2.west);
    }
    \foreach \n in {8,9}{
      \draw (B\n.east) -- (C3.west);
    }
    \foreach \n in {2,3}{
      \draw (C\n.east) -- (D2.west);
    }
  \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容