我有一个饼图,以拥挤的方式显示百分比数字,我想提高它的可读性。有办法吗?尤其是 6.29% 和 1.56% 的显示方式
\documentclass[sn-mathphys,Numbered,iicol]{sn-jnl}
\usepackage{tikz}
\input{Pie}
\begin{document}
\begin{figure*}
\centering
\begin{tikzpicture}
[
pie chart,
slice type={comet}{blu},
slice type={legno}{rosso},
slice type={coltello}{giallo},
slice type={sedia}{viola},
slice type={caffe}{verde},
slice type={C}{gray},
pie values/.style={font={\small}},
scale=2
]
\pie[xshift=2.2cm,values of caffe/.style={pos=1.1}]%
{}{38.57/comet,9.82/legno,37.79/sedia,5.88/C,6.29/caffe,1.56/coltello}
\end{tikzpicture}
\caption{xxxx.}
\label{tabI}
\end{figure*}
\end{document}
饼图内部代码
\usepackage{graphicx}%
\definecolor{rosso}{RGB}{220,57,18}
\definecolor{giallo}{RGB}{255,153,0}
\definecolor{blu}{RGB}{102,140,217}
\definecolor{verde}{RGB}{16,150,24}
\definecolor{viola}{RGB}{153,0,153}
\makeatletter
\tikzstyle{chart}=[
legend label/.style={font={\scriptsize},anchor=west,align=left},
legend box/.style={rectangle, draw, minimum size=5pt},
axis/.style={black,semithick,->},
axis label/.style={anchor=east,font={\tiny}},
]
\tikzstyle{bar chart}=[
chart,
bar width/.code={
\pgfmathparse{##1/2}
\global\let\bar@w\pgfmathresult
},
bar/.style={very thick, draw=white},
bar label/.style={font={\bf\small},anchor=north},
bar value/.style={font={\footnotesize}},
bar width=.75,
]
\tikzstyle{pie chart}=[
chart,
slice/.style={line cap=round, line join=round, very thick,draw=white},
pie title/.style={font={\bf}},
slice type/.style 2 args={
##1/.style={fill=##2},
values of ##1/.style={}
}
]
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\newcommand{\pie}[3][]{
\begin{scope}[#1]
\pgfmathsetmacro{\curA}{90}
\pgfmathsetmacro{\r}{1}
\def\c{(0,0)}
\node[pie title] at (90:1.3) {#2};
\foreach \v/\s in{#3}{
\pgfmathsetmacro{\deltaA}{\v/100*360}
\pgfmathsetmacro{\nextA}{\curA + \deltaA}
\pgfmathsetmacro{\midA}{(\curA+\nextA)/2}
\path[slice,\s] \c
-- +(\curA:\r)
arc (\curA:\nextA:\r)
-- cycle;
\pgfmathsetmacro{\d}{max((\deltaA * -(.5/50) + 1) , .5)}
\begin{pgfonlayer}{foreground}
\path \c -- node[pos=\d,pie values,values of \s]{$\v\%$} +(\midA:\r);
\end{pgfonlayer}
\global\let\curA\nextA
}
\end{scope}
}
\newcommand{\legend}[2][]{
\begin{scope}[#1]
\path
\foreach \n/\s in {#2}
{
++(0,-10pt) node[\s,legend box] {} +(5pt,0) node[legend label] {\n}
}
;
\end{scope}
}
答案1
以下答案使用轮图包,是我写的。
定义一个命令\WCtest
,其输出取决于百分比是否大于 7。此命令用于 和 键data
。wheel data
此处,使用 来获取百分比\WCperc
。
间隙是通过密钥获得的gap
。
\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\definecolor{rosso}{RGB}{220,57,18}
\definecolor{giallo}{RGB}{255,153,0}
\definecolor{blu}{RGB}{102,140,217}
\definecolor{verde}{RGB}{16,150,24}
\definecolor{viola}{RGB}{153,0,153}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\def\WCtest#1#2{%
\pgfmathparse{\WCpercentage>7?"#1":"#2"}%
\pgfmathresult%
}
\wheelchart[
counterclockwise,
data=\WCtest{}{\WCperc},
gap=0.02,
perc precision=2,
radius={0}{2.5},
wheel data=\WCtest{\WCperc}{}
]{%
38.59/blu/comet,
9.84/rosso/legno,
37.81/viola/sedia,
5.89/gray/C,
6.30/verde/caffe,
1.57/giallo/coltello%
}
\end{tikzpicture}
\end{document}