Wie ändere ich die Gradskalenwerte mit tkzKiviatDiagram?

Wie ändere ich die Gradskalenwerte mit tkzKiviatDiagram?

Ist es möglich, die tkzKiviatGrad-Skala so zu ändern, dass sie mit -2 statt mit 0 beginnt? Der Verkauf im folgenden Beispiel wäre also -2 -1 0 1 2.

Kann ich den Startpunkt außerdem irgendwie in der Mitte des Diagramms anzeigen?

\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}

Antwort1

Um das Problem zu lösen, schauen Sie sichtkz-kiviat.styund die Definition von \tkzKiviatGrad.

Ergebnis:

Bildbeschreibung hier eingeben

MWE:

\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. Wie ändere ich nur die Gradskalenwerte?(löst nur Problem 1)

\patchcmdSie können mit verwenden, \usepackage{etoolbox}um einen Befehl in .styeiner Datei neu zu definieren. Sie müssen Ihre Neudefinition mit \makeatletterund umgeben \makeatother, um auf Befehle zugreifen oder diese ändern zu können, deren Namen ein @-Zeichen enthalten. (Ref.:@Frank Mittelbachs Ansatz: .sty-Dateien ändern?

Um Ihren Maßstab von 0 1 2 3 4auf zu verschieben, -2 -1 0 1 2müssen Sie 2(vom berechneten Wert \pgfmathparseinnerhalb der \def\tkz@KiviatGradDefinition) mit der folgenden Neudefinition abziehen:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\tkz@KiviatGrad}{\pgfmathresult}{\pgfmathresult-2}
         {\typeout{*** SUCCESS ***}}
         {\ERRORpatchfailed}
\makeatother 

2. Startpunkt in der Mitte anzeigen(löst Problem 1 und 2)

Für die zweite Frage habe ich nur die Lösung gefunden, die gesamte Definition neu zu definieren. Da die for-loopVariable with mit i statt \nvmit beginnen muss , fügen Sie Ihrer Präambel Folgendes hinzu. Um auch Problem 1 auf die gleiche Weise zu lösen, ersetzen Sie es durch . : (Ref.:01\pgfmathtruncatemacro{\result}{\pgfmathresult}\pgfmathtruncatemacro{\result}{\pgfmathresult-2}@Werners Ansatz: lokale Neudefinition mit \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

verwandte Informationen