
“旭日圖 - 也稱為環形圖、多級餅圖和徑向樹圖 - 通常用於可視化分層資料結構。”
我所尋找的並不完全是上面的內容,而是它的概括。
我想為一篇論文創建一個簡單的情節。
它應該是向量圖形並且易於創建。
如果可能的話,我想在組件內添加文字。
這裡至少有兩個選擇(見下文)。如果你明白我的意思,也許也可以將其表達為某種「漩渦」...
如果我可以強調組件的重疊,即通過具有重疊的爆炸餅圖,那就太好了。
答案1
我想這可以稱為環形圖,就像圓形譜系圖一樣,它是從哪個項目產生的。這應該可以幫助您開始。封閉環境是onion
並且接受一個參數,即環的厚度(星形導致繪製 xy 軸)。此\annulus
巨集採用三個強制參數:層號(最內層為 0)、起始角度和結束角度,角度以逆時針方向指定。開頭還有一個可選參數用於填充顏色,末尾有一個可選參數用於文字。完整的命令可能如下所示:
\annulus[purple!20]{2}{165}{325}[more\\stuff]
(請參閱下面的程式碼)。
這裡沒什麼複雜的。鈦kZarc
函數完成大部分工作。
\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
%% |=====8><-----| %%
\newlength{\layerwd}
\newcounter{outermost}
%% |=====8><-----| %%
\NewDocumentEnvironment{onion}{sm}{%*= draw axes; #1: thickness of each annulus
\begin{tikzpicture}
\setlength{\layerwd}{#2}%
\setcounter{outermost}{0}
\IfBooleanT{#1}{%
\draw[<->] (-4,0) -- (4,0);
\draw[<->] (0,4) -- (0,-4);
}
}{%
\foreach \A in {0,...,\theoutermost}{\draw[thick] (0,0) circle (\A*\layerwd+\layerwd);}
\end{tikzpicture}
}
% *=unused; [optional fill color]; #3 layer; #4 start angle; #5 stop angle; #6 [optional text]
%% angles are counterclockwise in degrees
\NewDocumentCommand{\annulus}{sO{lightgray}mmmo}{%
\filldraw[thick,fill=#2] (#4:#3*\layerwd) %% start here
arc [radius=#3*\layerwd, start angle=#4, delta angle=#5-#4] %% inner arc
-- (#5:#3*\layerwd+\layerwd) %% move out
arc [radius=#3*\layerwd+\layerwd, start angle=#5, delta angle=#4-#5] %% outer arc
-- cycle; %% Back to the beginnning
\pgfmathsetmacro{\tmp}{(#5-#4)/2 +#4} %% Locate the middle of the arc
\IfNoValueF{#6}{\node[inner sep=0pt, %%% If there is text, print it
text width=#3*\layerwd*3+\layerwd,
align=center,
rotate=\tmp-90,
font=\footnotesize] at (\tmp:#3*\layerwd+0.5*\layerwd)
{#6}; %% Options text, rotated, in the middle of the arc
}%
\ifnum\theoutermost<#3\setcounter{outermost}{#3}\fi
}
%% |=====8><-----| %%
\begin{document}
\begin{onion}*{0.25in}
\annulus{0}{0}{90}[1]
\annulus{0}{90}{180}[2]
\annulus{0}{180}{270}[3]
\annulus{0}{270}{360}[4]
\annulus[yellow]{1}{0}{120}[Y]
\annulus[red!20]{4}{0}{90}
\annulus[blue!30]{3}{60}{180}
\annulus[cyan!20]{2}{45}{130}
\annulus[purple!20]{2}{165}{325}[more\\stuff]
\end{onion}
\end{document}
更新
創建環形圖表而不利用 Ti 似乎很奇怪kZ 將文字放置在路徑上的能力。唯一的變化是\annulus
巨集可以採用可選值*
將可選文字放置在圓形路徑上。請注意,路徑上的文字不能有換行符號;\\
會導致 TeX 掛起——我已經在有限的程度上防範了這種可能性。
\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usetikzlibrary{decorations, decorations.text}
%% |=====8><-----| %%
\newlength{\layerwd}
\newcounter{outermost}
%% |=====8><-----| %%
\NewDocumentEnvironment{onion}{sm}{%*= draw axes; #1: thickness of each annulus
\begin{tikzpicture}
\setlength{\layerwd}{#2}%
\setcounter{outermost}{0}
\IfBooleanT{#1}{%
\draw[<->] (-4,0) -- (4,0);
\draw[<->] (0,4) -- (0,-4);
}
}{%
\foreach \A in {0,...,\theoutermost}{\draw[thick] (0,0) circle (\A*\layerwd+\layerwd);}
\end{tikzpicture}
}
% *=text on a circular path; [optional fill color]; #3 layer;
% #4 start angle; #5 stop angle; #6 [optional text]
%% angles are counterclockwise in degrees
\NewDocumentCommand{\annulus}{sO{lightgray}mmmo}{%
\filldraw[thick,fill=#2] (#4:#3*\layerwd) %% start here
arc [radius=#3*\layerwd, start angle=#4, delta angle=#5-#4] %% inner arc
-- (#5:#3*\layerwd+\layerwd) %% move out
arc [radius=#3*\layerwd+\layerwd, start angle=#5, delta angle=#4-#5] %% outer arc
-- cycle; %% Back to the beginnning
\pgfmathsetmacro{\tmp}{(#5-#4)/2 +#4} %% Locate the middle of the arc
\IfNoValueF{#6}{%
\IfBooleanTF{#1}
{%
\begingroup
\def\\{\space} %% A safety precaution, \\ = space on decorated text
\path[rotate=\tmp-180,postaction={
decorate,
decoration={
text along path,
raise=-3pt,
text align={align=center},
reverse path=true,
text=#6
}
}] (0,0) circle (#3*\layerwd+0.5*\layerwd);
\endgroup
}%%
{%
\node[inner sep=0pt, %%% If there is text, print it
text width=#3*\layerwd*3+\layerwd,
align=center,
rotate=\tmp-90,
font=\footnotesize] at (\tmp:#3*\layerwd+0.5*\layerwd)
{#6};
}%
}%
\ifnum\theoutermost<#3\setcounter{outermost}{#3}\fi
}
%% |=====8><-----| %%
\begin{document}
\begin{onion}*{0.25in}
\annulus{0}{0}{90}[1]
\annulus{0}{90}{180}[2]
\annulus{0}{180}{270}[3]
\annulus{0}{270}{360}[4]
\annulus*[yellow]{1}{0}{120}[Y is yellow]
\annulus*[red!20]{4}{0}{90}[This is a bunch of bla bla]
\annulus*[blue!30]{3}{60}{180}[This is some longer text]
\annulus[cyan!20]{2}{45}{130}
\annulus[purple!20]{2}{165}{325}[more\\stuff]
\end{onion}
\end{document}
更新2
進行了一個小更改,確保圖表下半部分的文字正面朝上。
\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usetikzlibrary{decorations, decorations.text}
%% |=====8><-----| %%
\newlength{\layerwd}
\newcounter{outermost}
%% |=====8><-----| %%
\NewDocumentEnvironment{onion}{sm}{%*= draw axes; #1: thickness of each annulus
\begin{tikzpicture}
\setlength{\layerwd}{#2}%
\setcounter{outermost}{0}
\IfBooleanT{#1}{%
\draw[<->] (-4,0) -- (4,0);
\draw[<->] (0,4) -- (0,-4);
}%
}{%
\foreach \A in {0,...,\theoutermost}{\draw[thick] (0,0) circle (\A*\layerwd+\layerwd);}
\end{tikzpicture}
}
% *=text on a circular path; [optional fill color]; #3 layer;
% #4 start angle; #5 stop angle; #6 [optional text]
%% angles are counterclockwise in degrees
\NewDocumentCommand{\annulus}{sO{lightgray}mmmo}{%
\filldraw[thick,fill=#2] (#4:#3*\layerwd) %% start here
arc [radius=#3*\layerwd, start angle=#4, delta angle=#5-#4] %% inner arc
-- (#5:#3*\layerwd+\layerwd) %% move out
arc [radius=#3*\layerwd+\layerwd, start angle=#5, delta angle=#4-#5] %% outer arc
-- cycle; %% Back to the beginnning
\pgfmathsetmacro{\tmp}{(#5-#4)/2 +#4} %% Locate the middle of the arc
\IfNoValueF{#6}{%
\IfBooleanTF{#1}
{%
\begingroup
%% text is always rightside-up:
\pgfmathsetmacro{\rpTF}{ifthenelse(\tmp>180,"false","true")}
\def\\{\space} %% A safety precaution, \\ = space on decorated text
\path[rotate=\tmp-180,postaction={
decorate,
decoration={
text along path,
raise=-3pt,
text align={align=center},
reverse path=\rpTF,
text=#6
}
}] (0,0) circle (#3*\layerwd+0.5*\layerwd);
\endgroup
}%%
{%
\pgfmathsetmacro{\rpTF}{ifthenelse(\tmp>180,\tmp+90,\tmp-90)}
\node[inner sep=0pt, %%% If there is text, print it
text width=#3*\layerwd*3+\layerwd,
align=center,
rotate=\rpTF,
font=\footnotesize] at (\tmp:#3*\layerwd+0.5*\layerwd)
{#6};
}%
}%
\ifnum\theoutermost<#3\setcounter{outermost}{#3}\fi
}
%% |=====8><-----| %%
\begin{document}
\begin{onion}*{0.3in}
\annulus{0}{0}{90}[1]
\annulus{0}{90}{180}[2]
\annulus{0}{180}{270}[3]
\annulus{0}{270}{360}[4]
\annulus*[yellow]{1}{0}{120}[Y is yellow]
\annulus*[red!20]{4}{0}{135}[This is a bunch of bla bla]
\annulus*[blue!30]{3}{60}{180}[This is some longer text]
\annulus[cyan!20]{2}{45}{130}
\annulus[white]{3}{225}{315}[Line 1\\Line 2]
\annulus*[purple!20]{2}{165}{325}[more\\stuff]
\end{onion}
\end{document}