是否有可能得到如下图表
-这是输出- (整个矩形的面积为“100%”)
从虚构数据如
data name color
22 A gray
5 C blue
5 D orange
-这是输入-
MWE 输出错误:
\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
]
\addplot[xtick=data,] table[y index=0] {
data name color
22 A gray
5 C blue
5 D orange
};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
安装后pgf-派我得到了一个不错的方形饼。
但是该包在某些细节上不够灵活。
\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture}[xscale = 1.75,
font=\sffamily,
mystyle/.style={draw=white, very thick, text=white, font=\sffamily\bfseries},
]
\pie[square,
style={mystyle},
color={yellow!80!orange, gray, blue!40, orange},
%text=inside,
text=legend,
]{68/A, 5/B, 5/C, 22/D}
\end {tikzpicture}
\end{document}
答案2
首次尝试使用 pgfplots 和矩形改编自 --https://tex.stackexchange.com/a/344816/197451
数学家协会
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% use `compat' level 1.11 or higher so coordinates don't have to be
% prefixed with `axis cs:' (any more)
compat=1.11,
}
\begin{document}
\begin{tikzpicture}[
region/.style={
draw=black!50,
dashed,
},
Node/.style={
midway,
red,
},
declare function={
xmin=0;
xmax=12;
ymin=0;
ymax=300;
},
]
\begin{axis}[hide axis,
xlabel={},
ylabel={},
xmin=xmin,
xmax=xmax,
ymin=ymin,
ymax=ymax,
axis background/.style={},
extra x ticks={},
extra y ticks={},
title=title,
]
\draw [region,fill=brown!40] (xmin,ymin) rectangle (8,ymax) node [Node, xshift=-55, yshift=-76] {68\%};
\draw [region,fill=blue!40] (8,ymin) rectangle (10,50) node [Node, xshift=-10, yshift=-9] {5\%};
\draw [region,fill=red!40] (10,ymin) rectangle (xmax,50) node [Node, xshift=-10, yshift=-9] {5\%};
\draw [region,fill=gray!40] (8,50) rectangle (xmax,ymax) node [Node, xshift=-24, yshift=-64] {22\%};
\end{axis}
\end{tikzpicture}
\end{document}