我想为我已有的饼图构建宏环境。这样我就可以轻松多次使用。我已经有一个生成饼图/环形图的代码。如果有用于弧角/大小、颜色、弧标签和中心圆形节点标签的宏就太好了。我将不胜感激所有帮助。这是我的 MWE:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[font=\sffamily\bfseries\large, text=white, border/.style={line width=12mm}]
\foreach \angle/\colour/\name [remember=\angle as \first (initially 0)] in {40/blue, 90/cyan, 160/green!30!black, 200/green, 240/orange, 295/red!70, 360/teal}{
\draw[\colour, border] (\first:1.5cm)
arc[start angle=\first, end angle=\angle, radius=1.5cm];
\draw[white, line width=1mm] (\first:0.8)--++(\first:1.8);
}
\node[line width=1mm, draw, circle, minimum width=1.7cm, white, fill=blue!80] {A};
\node at (20:1.5cm) {A1};
\node at (62:1.6cm) {A2};
\node at (125:1.5cm) {A3};
\node at (180:1.5cm) {A4};
\node at (221:1.5cm) {A5};
\node at (268:1.5cm) {A6};
\node at (330:1.5cm) {A7};
\end{tikzpicture}
\end{document}
这是我的代码目前正在生成的饼图。
答案1
看起来我的代码很有用。很好!
此代码可适应两个\newcommand
带有两个参数的a。
\mypie
有两个参数,第一个是三元组列表end-angle/color/contents
,第二个是要添加两个中心节点(可以是fill=..., node contents=...
)的选项。
\documentclass[tikz,border=2mm]{standalone}
%\usepackage{xcolor} %<- already loaded by TikZ
\usepackage{tikz}
\newcommand{\mypie}[2]{
\begin{tikzpicture}[font=\sffamily\bfseries\large,
text=white, border/.style={line width=12mm}]
\foreach \angle/\colour/\name [remember=\angle as \first (initially 0)] in {#1}{
\draw[\colour, border] (\first:1.5cm)
arc[start angle=\first, end angle=\angle, radius=1.5cm];
\node[white] at ({(\angle+\first)/2}:1.5) {\name};
\draw[white, line width=1mm] (\first:0.8)--++(\first:1.8);
}
\node[line width=1mm, draw, circle, minimum width=1.7cm, white, #2];
\end{tikzpicture}
}
\begin{document}
\mypie{40/blue/A1, 90/cyan/A2, 160/green!30!black/A3,
200/green/A4, 240/orange/A5, 295/red!70/A6,
360/teal/A7}{fill=red!30, node contents=A}
\mypie{45/blue/A1, 100/cyan/A2, 200/green!30!black/A3,
300/green/A4, 360/orange/A5}{fill=purple!60, node contents=Z}
\end{document}