3

MWE

\documentclass[border=10pt]{standalone}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usetikzlibrary{arrows}
\thispagestyle{empty}

\begin{document} 

\begin{tikzpicture}
\tkzKiviatDiagram[
radial  = 5,
gap     = 1,  
lattice = 5]{CO1,CO2,CO3,CO4,CO5}

\tkzKiviatLine[
ultra thick, 
color=blue, 
mark=ball,
mark size=4pt,
fill=blue!20,opacity=.5
](3,3.5,3,4,3.8)

\tkzKiviatGrad[prefix=,unity=1](5) 

\end{tikzpicture}
\end{document} 

RESULT

enter image description here


How to add the values 3, 3.5, 3, 4 and 3.8 near corresponding points...

Bobyandbob
  • 4,899
sandu
  • 7,950

2 Answers2

6

The following example uses some internals to define a coordinate system with options rang for the number of the axes and the value. Then the labels are placed at appropriate locations. The example also hacks into \tkzKiviatLine to remember the value list that is needed in the second example.

\documentclass[border=10pt]{standalone}

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\thispagestyle{empty}

\makeatletter
\let\org@tkz@KiviatLine\tkz@KiviatLine
\def\tkz@KiviatLine[#1](#2,#3){%
  \def\KiviatValues{#2,#3}%
  \org@tkz@KiviatLine[{#1}]({#2},{#3})%
}

\newcommand*{\KiviatRadial}{\tkz@kiv@radial}

\define@key{kiviatkeys}{rang}{\pgfmathsetmacro\kiviat@rang{#1}}
\define@key{kiviatkeys}{value}{\pgfmathsetmacro\kiviat@value{#1}}
\tikzdeclarecoordinatesystem{kiviat}{%
  \setkeys{kiviatkeys}{#1}%
  \pgfpointpolarxy{%
    360/\tkz@kiv@radial*\kiviat@rang
  }{%
    \kiviat@value*\tkz@kiv@gap*\tkz@kiv@step
  }%
}
\makeatother

\begin{document} 

\begin{tikzpicture}
\tkzKiviatDiagram[
  radial  = 5,
  gap     = 1,
  lattice = 5,
]{CO1,CO2,CO3,CO4,CO5}

\tkzKiviatLine[
  ultra thick, 
  color=blue, 
  mark=ball,
  mark size=4pt,
  fill=blue!20,opacity=.5,
](3,3.5,3,4,3.8)

\tkzKiviatGrad[prefix=,unity=1](5) 

\def\x(#1,#2)[#3]{%
  (kiviat cs:rang=#1, value=#2) node[#3] {#2}%
}
\path
  \x(0, 3)[above right]
  \x(1, 3.5)[above left]
  \x(2, 3)[below left=-.2em and .2em]
  \x(3, 4)[below=.3em]
  \x(4, 3.8)[below right=-.1em and .1em]
;

\end{tikzpicture}
\end{document} 

Result

An algorithm that looks for the optimal placement of the labels is much more cumbersome. The axis angle, the value, the size of the label, the connecting lines to the neighboring points have to be taken into account. Therefore, the following example is just a first step that simply places the labels near the points on the axes in the outside direction.

\path
  \foreach \v [count=\rang from 0] in \KiviatValues {
    ($(kiviat cs:rang=\rang, value=\v)!-.55em!(0, 0)$)
    node[
      anchor=360/\KiviatRadial*\rang-180,
      circle,
      inner sep=.1em,
      fill=white,
    ] {\v}
  }
;

Result

The same with the normal white background:

Result

Heiko Oberdiek
  • 271,626
  • Interesting the automatic way to positioning the labels but maybe a white background could be helpful because some numbers are over the axis. Maybe... I don't know! Nice! – Sigur Jul 29 '17 at 10:50
  • 1
    @Sigur I had tried with a white background, but the label placement was too bad. I have now fixed the label placement by using anchor and added a white background. – Heiko Oberdiek Jul 29 '17 at 11:00
3

Labeling command: \tkzKiviatLabeling{<axis>}{<distance/pos>}{<label>} So you could use \tkzKiviatLabeling{2}{3.5}{3.5} to set the label 3.5 on axis CO2 (second axis). With \tkzKiviatAxisAngAdd you can rotate the label position default is 4 degree. The distance on the axis is 3.5 plus the value of \tkzKiviatAxisDistAdd(to add aditional space between the point an

near each ball parameters: to reduce overlapping problems

  • \tkzKiviatAxisDistAdd: radial distance between point and label
  • \tkzKiviatAxisAngAdd: angle between the axis and the label

The values could be predefined with a array \def\Values{{3,3.5,3,4,3.8}}(used later in the lebeling loop), it doesn't work ith \tkzKiviatLine[ so you have to add the values like in the question.

labeling loop:

  \foreach[count=\i from 1] \x in {1,...,\tkzKiviatAxisCount}{ 
    \pgfmathparse{\Values[\i-1]}\edef\saveresult{\pgfmathresult}
    \tkzKiviatLabeling{\i}{\saveresult}{\saveresult}
    }

Result:

enter image description here

MWE:

\documentclass[border=10pt]{standalone}
\usepackage{tkz-kiviat}
\usetikzlibrary{arrows}
\newcommand{\tkzKiviatAxisCount}{5}
\newcommand{\tkzKiviatAxisDistAdd}{\tkzKiviatAxisCount/10}%or value like 5...
\newcommand{\tkzKiviatAxisAngAdd}{4}%degree
\newcommand{\tkzKiviatLabeling}[3]{
\pgfmathsetmacro{\kivaxisangle}{360/\tkzKiviatAxisCount}
\pgfmathtruncatemacro{\direction}{#1-1}             
    \node at (\kivaxisangle*\direction+\tkzKiviatAxisAngAdd:#2+\tkzKiviatAxisDistAdd) {#3};
}
\def\Values{{3,3.5,3,4,3.8}}
\begin{document} 
\begin{tikzpicture}
\tkzKiviatDiagram[radial=\tkzKiviatAxisCount,gap=1,lattice = \tkzKiviatAxisCount]{CO1,CO2,CO3,CO4,CO5}
\tkzKiviatLine[ultra thick,color=blue,mark=ball,mark size=4pt,fill=blue!20,opacity=.5](3,3.5,3,4,3.8)        
\tkzKiviatGrad[prefix=,unity=1](\tkzKiviatAxisCount) 
%auto:
\foreach[count=\i from 1] \x in {1,...,\tkzKiviatAxisCount}{ 
\pgfmathparse{\Values[\i-1]}\edef\saveresult{\pgfmathresult}
\tkzKiviatLabeling{\i}{\saveresult}{\saveresult}
}
% manu:
%    \tkzKiviatLabeling{1}{3}{3}
%    \tkzKiviatLabeling{2}{3.5}{3.5}
%    \tkzKiviatLabeling{3}{3}{3}
%    \tkzKiviatLabeling{4}{4}{4}
%    \tkzKiviatLabeling{5}{3.8}{3.8}
\end{tikzpicture}
\end{document} 
Bobyandbob
  • 4,899