是否可以将 tkzKiviatGrad 比例改为从 -2 开始而不是从 0 开始?因此,以下示例中的销售额将是 -2 -1 0 1 2。
另外,我可以以某种方式显示图表中心的起点吗?
\documentclass{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{tkz-kiviat}
\usetikzlibrary{arrows,positioning,fit}
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\tkzKiviatDiagram[scale=0.8,label distance=1cm,
gap = 1.5,
lattice = 4]{Barfoo1,Barfoo2,Barfoo3,Barfoo4,Barfoo5,Barfoo6}
\tkzKiviatLine[thick,color=blue](1,2,3,2,4,0)
\tkzKiviatLine[thick,color=yellow](1,2,4,1,4,2)
\tkzKiviatLine[thick,color=green](1,4,4,2,4,4)
\tkzKiviatLine[thick,color=Aquamarine](1,2,3,1,2,2)
\tkzKiviatLine[thick,color=Magenta](1,3,4,1,4,3)
\tkzKiviatGrad[unity=1](0)
\node[anchor=south west,xshift=-60pt,yshift=40pt] at (current bounding box.south east)
{
\begin{tabular}{@{}lp{4cm}@{}}
\cellcolor{blue} & Foobar1 \\
\cellcolor{yellow} & Foobar2 \\
\cellcolor{green} & Foobar3\\
\cellcolor{Aquamarine} & Foobar4 \\
\cellcolor{Magenta} & Foobar5 \\
\end{tabular}
};
\end{tikzpicture}
\end{figure}
\end{document}
答案1
要解决问题,请查看tkz-kiviat.sty以及 的定义\tkzKiviatGrad
。
结果:
梅威瑟:
\documentclass{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{tkz-kiviat}
\usetikzlibrary{arrows}
\makeatletter
\def\tkzKiviatGrad{\pgfutil@ifnextchar[{\tkz@KiviatGrad}{\tkz@KiviatGrad[]}}
\def\tkz@KiviatGrad[#1](#2){%
\begingroup
\pgfkeys{/kiviatgrad/.cd,
graduation distance= 0 pt,
prefix ={},
suffix={},
unity=1
}
\pgfqkeys{/kiviatgrad}{#1}%
\let\tikz@label@distance@tmp\tikz@label@distance
\global\let\tikz@label@distance\tkz@kiv@grad
\foreach \nv in {0,...,\tkz@kiv@lattice}{ %original: \foreach \nv in {1,...,\tkz@kiv@lattice}{
\pgfmathparse{\tkz@kiv@unity*\nv}
\pgfmathtruncatemacro{\result}{\pgfmathresult-2} %original: \pgfmathtruncatemacro{\result}{\pgfmathresult}
\protected@edef\tkz@kiv@gd{\tkz@kiv@prefix$\result$\tkz@kiv@suffix}
\path[/kiviatgrad/.cd,#1] (0:0)--(360/\tkz@kiv@radial*#2:\nv*\tkz@kiv@gap)
node[label=(360/\tkz@kiv@radial*#2)-90:\tkz@kiv@gd] {};
}
\let\tikz@label@distance\tikz@label@distance@tmp
\endgroup
}%
\makeatother
% \usepackage{etoolbox}
% \makeatletter
% \patchcmd{\tkz@KiviatGrad}{\pgfmathresult}{\pgfmathresult-2}
% {\typeout{*** SUCCESS ***}}
% {\ERRORpatchfailed}
% \makeatother
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\tkzKiviatDiagram[scale=0.8,label distance=1cm,
gap = 1.5,
lattice = 4]{Barfoo1,Barfoo2,Barfoo3,Barfoo4,Barfoo5,Barfoo6}
\tkzKiviatLine[thick,color=blue](1,2,3,2,4,0)
\tkzKiviatLine[thick,color=yellow](1,2,4,1,4,2)
\tkzKiviatLine[thick,color=green](1,4,4,2,4,4)
\tkzKiviatLine[thick,color=Aquamarine](1,2,3,1,2,2)
\tkzKiviatLine[thick,color=Magenta](1,3,4,1,4,3)
\tkzKiviatGrad[unity=1](0)
\node[anchor=south west,xshift=-60pt,yshift=40pt] at (current bounding box.south east)
{
\begin{tabular}{@{}lp{4cm}@{}}
\cellcolor{blue} & Foobar1 \\
\cellcolor{yellow} & Foobar2 \\
\cellcolor{green} & Foobar3\\
\cellcolor{Aquamarine} & Foobar4 \\
\cellcolor{Magenta} & Foobar5 \\
\end{tabular}
};
\end{tikzpicture}
\end{figure}
\end{document}
1. 如何仅改变梯度值?(仅解决问题 1)
您可以使用\patchcmd
with\usepackage{etoolbox}
重新定义文件内的命令.sty
。您必须用\makeatletter
and包围重新定义\makeatother
,以便能够访问或修改名称中包含 @ 符号的命令。(参考:@Frank Mittelbach 的方法:修改.sty 文件?
要将您的比例从 转移0 1 2 3 4
到 ,-2 -1 0 1 2
您必须使用下面的重新定义减去2
(从定义\pgfmathparse
内部的计算值\def\tkz@KiviatGrad
):
\usepackage{etoolbox}
\makeatletter
\patchcmd{\tkz@KiviatGrad}{\pgfmathresult}{\pgfmathresult-2}
{\typeout{*** SUCCESS ***}}
{\ERRORpatchfailed}
\makeatother
2. 中心显示起点(解决问题 1 和 2)
对于第二个问题,我只找到了重新定义整个定义的解决方案。因为for-loop
with 变量\nv
必须以 i 开头,0
而不是,1
所以将以下内容添加到您的序言中。要解决问题 1,请以相同的方式将其替换\pgfmathtruncatemacro{\result}{\pgfmathresult}
为\pgfmathtruncatemacro{\result}{\pgfmathresult-2}
. : (参考:@Werner 的方法:使用 \makeatletter 进行本地重新定义... \makeatother
\makeatletter
\def\tkzKiviatGrad{\pgfutil@ifnextchar[{\tkz@KiviatGrad}{\tkz@KiviatGrad[]}}
\def\tkz@KiviatGrad[#1](#2){%
\begingroup
\pgfkeys{/kiviatgrad/.cd,
graduation distance= 0 pt,
prefix ={},
suffix={},
unity=1
}
\pgfqkeys{/kiviatgrad}{#1}%
\let\tikz@label@distance@tmp\tikz@label@distance
\global\let\tikz@label@distance\tkz@kiv@grad
\foreach \nv in {0,...,\tkz@kiv@lattice}{ %original: \foreach \nv in {1,...,\tkz@kiv@lattice}{
\pgfmathparse{\tkz@kiv@unity*\nv}
\pgfmathtruncatemacro{\result}{\pgfmathresult-2} %original: \pgfmathtruncatemacro{\result}{\pgfmathresult}
\protected@edef\tkz@kiv@gd{\tkz@kiv@prefix$\result$\tkz@kiv@suffix}
\path[/kiviatgrad/.cd,#1] (0:0)--(360/\tkz@kiv@radial*#2:\nv*\tkz@kiv@gap)
node[label=(360/\tkz@kiv@radial*#2)-90:\tkz@kiv@gd] {};
}
\let\tikz@label@distance\tikz@label@distance@tmp
\endgroup
}%
\makeatother