答案1
在 Covid-19 期间放松一下。
\documentclass[tikz,border=5mm]{standalone}
\usepackage[utf8]{vietnam}
\usepackage{amsmath,amssymb,amsthm}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\def\r{3}
\pgfmathsetmacro{\a}{12*360/100}
\fill[red!70] (0,0) circle(\r);
\fill[orange] (0,0)--(90:\r) arc(90:{90-\a}:\r)--cycle;
\pgfmathsetmacro{\b}{45*360/100}
\fill[lime!80!black] (0,0)--(90-\a:\r) arc(90-\a:{90-\a-\b}:\r)--cycle;
\pgfmathsetmacro{\c}{36*360/100}
\fill[cyan] (0,0)--(90-\a-\b:\r) arc(90-\a-\b:{90-\a-\b-\c}:\r)--cycle;
\fill[white] (0,0) circle(\r/2);
\path (current bounding box.north) node[above=5mm,font=\sffamily]
{Average Daily Activity};
\end{tikzpicture}
\begin{tikzpicture}[rect/.pic={\draw[#1,line width=3mm] (90:.25)--(-90:.25);}]
\matrix (m) [matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={minimum height=8mm,minimum width=3cm,anchor=center,font=\sffamily,text=black!80},
column 2/.style={nodes={text width=4mm,align=right}},
column 3/.style={nodes={minimum width=2cm,text width=10mm,align=right}},
row 1/.style={nodes={font=\bfseries\sffamily,text width=2cm,text=black,align=center}},
]{
Hours & \% & Total\\
5am - 11am&12&6.158\\
11am - 5pm&45&22.168\\
5pm - 11pm&36&18.015\\
11pm - 5am&6&3.078\\
};
\foreach \i/\icolor in {2/orange,3/lime!80!black,4/cyan,5/red!70}
\draw[gray]
(m-\i-1.north west)--(m-\i-3.north east)
(m-\i-1.west)+(0:.2) pic{rect=\icolor};
\draw[gray]
(m-5-1.south west)--(m-5-3.south east);
\end{tikzpicture}
\end{document}
答案2
薛定谔的猫说,从pgf-pie
手动的你可以得到非常接近你要求的结果。幸运的是,我昨天刚好做了一个。
\documentclass[tikz]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture}[]
\pie[text=legend,sum=100,rotate=40,radius=2.5,
before number=\phantom,after number=,
] {
12/{5am -- 11am},
45/{11am -- 5pm},
36/{5pm -- 11pm},
6/{11pm -- 5am}
}
\path[fill=white,draw=black, thick] (0,0) circle (1.5);
\end{tikzpicture}
\end{document}
draw=none
但是,我不知道为什么,即使使用某些键,我也无法修改线条的样式every path/.append style
。
答案3
这轮图我写的包,可以使用。
图例由键决定legend
。这是一个tabular
放置在 中的\node
。行由键决定legend row
。可以使用 获得所有行的结果\WClegend
。
\documentclass[border=6pt,dvipsnames]{standalone}
\usepackage{wheelchart}
\usepackage{tabularray}
\UseTblrLibrary{counter,siunitx}
\sisetup{group-separator={,},group-minimum-digits=4,text-series-to-math=true}
\begin{document}
\begin{tikzpicture}
\sffamily
\wheelchart[
data=,
legend row={\tikz\fill[\WCvarB] (0,0) rectangle (0.3,0.3); & \WCvarC & \WCvarD & \WCperc & \WCvarA},
legend={
\node[anchor=north] at (0,-2.5) {%
\begin{tblr}[expand=\WClegend]{
colspec={lrlrS[table-format=5.0]},
column{2}={rightsep=0pt},
cell{2-Z}{2}={appto={--}},
column{3}={leftsep=0pt},
row{1}={guard,font=\bfseries}
}
& \SetCell[c=2]{c} Hours & & \SetCell[c=1]{c} \unit{\percent} & Total\\\hline
\WClegend\hline
\end{tblr}%
};
},
radius={1}{2},
title=Average Daily Activity
]{%
6158/BurntOrange/5am/11am,
22168/SpringGreen/11am/5pm,
18015/Cerulean/5pm/11pm,
3078/Maroon/11pm/5am%
}
\end{tikzpicture}
\end{document}