![TiKz Kiviat 图表 - 标签编号从 0.0 到 1.0](https://linux22.com/image/360996/TiKz%20Kiviat%20%E5%9B%BE%E8%A1%A8%20-%20%E6%A0%87%E7%AD%BE%E7%BC%96%E5%8F%B7%E4%BB%8E%200.0%20%E5%88%B0%201.0.png)
我正在尝试创建一个 Kiviat 图。轴的标签值必须从 0.0 到 1.0。我用过,\pgfmathresult/10
但只得到整数。
下面我展示了我正在使用的代码。有人能帮我获取从 0.0 到 1.0 的标签值吗
\documentclass{article}
\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\newcommand\ColorBox[1]{\textcolor{#1}{\rule{2ex}{2ex}}}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{etoolbox}
\usetikzlibrary{calc}
\begin{document}
\makeatletter
\patchcmd{\tkz@KiviatGrad}{\pgfmathresult}{\pgfmathresult/10}
{\typeout{*** SUCCESS ***}}
{\ERRORpatchfailed}
\makeatother
\begin{figure}[!h]
\centering
\frame{
\begin{tikzpicture}[label distance=.15cm, scale=0.5]
\tkzKiviatDiagram[radial style/.style ={-}, lattice style/.style ={black!30}]%
{$Q_u$, $Q_c$, $Q_d$, $Q_{da}$, $Q_m$, $Q_p$, $Q_t$}
\tkzKiviatLine[thick,color=red!20,
mark=ball,
ball color=red!20,
mark size=4pt,
fill=red!20](8,7.5,10,10,9,9,7.5)
\tkzKiviatLine[thick,color=blue!20,mark=ball,
mark size=4pt,
mark color=blue!20,
fill=blue!20,
opacity=.5](8.6,9,10,10,8,5,5)
\tkzKiviatGrad[suffix=,unity=1](0)
\end{tikzpicture}}
\end{figure}
结果是:
答案1
您所做的更改不起作用,因为下一步中\tkz@KiviatGrad
使用了。您需要将其更改为。因为这给我带来了一些精度问题(例如,而不是),所以我后来格式化了数字。由于空间不大,我将标签移动到了第二个轴,并将字体大小减小到了。注意,我设置了而不是除以 10 。\pgfmathtruncatemacro
\pgfmathsetmacro
0.20001
0.2
\pgfmathprintnumber
\tiny
unity=0.1
\tkz@KiviatGrad
参见代码中的注释。
\documentclass{article}
\usepackage{tkz-kiviat}
\makeatletter
\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 {1,...,\tkz@kiv@lattice}{
\pgfmathparse{\tkz@kiv@unity*\nv}
\pgfmathsetmacro{\result}{\pgfmathresult} % change from \pgfmathtruncatemacro
\protected@edef\tkz@kiv@gd{\tkz@kiv@prefix\pgfmathprintnumber[precision=1,fixed]{\result}\tkz@kiv@suffix} % used \pgfmathprintnumber instead of "$\result$"
\path[/kiviatgrad/.cd,#1] (0:0)--(360/\tkz@kiv@radial*#2:\nv*\tkz@kiv@gap)
node[label=(360/\tkz@kiv@radial*#2)-90:\tiny\tkz@kiv@gd] {}; % added \tiny
}
\let\tikz@label@distance\tikz@label@distance@tmp
\endgroup
}%
\makeatother
\begin{document}
\begin{figure}[!h]
\centering
\frame{
\begin{tikzpicture}[label distance=.15cm,scale=0.5]
\tkzKiviatDiagram[radial style/.style ={-}, lattice style/.style ={black!30}]%
{$Q_u$, $Q_c$, $Q_d$, $Q_{da}$, $Q_m$, $Q_p$, $Q_t$}
\tkzKiviatGrad[unity=0.1](1) % set unity as 0.1
\end{tikzpicture}}
\end{figure}
\end{document}