![蜘蛛网/Kiviat 图表 - 图例周围的方框](https://linux22.com/image/339198/%E8%9C%98%E8%9B%9B%E7%BD%91%2FKiviat%20%E5%9B%BE%E8%A1%A8%20-%20%E5%9B%BE%E4%BE%8B%E5%91%A8%E5%9B%B4%E7%9A%84%E6%96%B9%E6%A1%86.png)
如何用线条代替节点来制作图例周围的框?我有点困惑。
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{pgfplots}
\usetikzlibrary{arrows,fit}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\newcommand{\LegendBox}[3][]{%
\xdef\fitbox{}%
\coordinate[#1] (LegendBox_anchor) at (#2) ;
\foreach \col/\item [count=\hi from 0] in {#3} {
\draw[line width=3mm,color=\col] ([yshift=\hi*8mm]LegendBox_anchor) -- ++(.5,0)
node[anchor=west][color=black] {\item}
;}
\node [draw,fit=\fitbox(LegendBox_anchor)]{};
}
\begin{document}
\begin{tikzpicture}[label distance=.15cm,scale=0.75]
\begin{scope}[rotate=30]
\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
{Cover,
Droppings,
Other}
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02)
\tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06)
\tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6)
\tkzKiviatGrad[suffix=\%,unity=10](0)
\end{scope}
\LegendBox[shift={(-3cm,-3cm)}]{current bounding box.south east}%
{red/red decription,
blue/blue description,
green/green }
\end{tikzpicture}
\end{document}
答案1
通过手动调整,您可以从坐标系(LegendBox_anchor)
绘制一个包含图例的矩形
只需更换
\node [draw,fit=\fitbox(LegendBox_anchor)]{};
和
\draw ([shift={(-.2,-.4)}]LegendBox_anchor)rectangle([shift={(4.5,2)}]LegendBox_anchor);
在这种情况下你不需要fit
库
代码
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\newcommand{\LegendBox}[3][]{%
\coordinate[#1] (LegendBox_anchor) at (#2) ;
\foreach \col/\item [count=\hi from 0] in {#3} {
\draw[line width=3mm,color=\col] ([yshift=\hi*8mm]LegendBox_anchor) -- ++(.5,0)
node[anchor=west][color=black] {\item}
;}
\draw ([shift={(-.2,-.4)}]LegendBox_anchor)rectangle([shift={(4.5,2)}]LegendBox_anchor);
}
\begin{document}
\begin{tikzpicture}[label distance=.15cm,scale=0.75]
\begin{scope}[rotate=30]
\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
{Cover,
Droppings,
Other}
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02)
\tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06)
\tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6)
\tkzKiviatGrad[suffix=\%,unity=10](0)
\end{scope}
\LegendBox[shift={(-3cm,-3cm)}]{current bounding box.south east}%
{red/red decription,
blue/blue description,
green/green }
\end{tikzpicture}
\end{document}
输出