如何在 tkzKiviatDiagram 中制作图例?

如何在 tkzKiviatDiagram 中制作图例?

我使用 tkzKiviatDiagrm 绘制了雷达图。

\begin{figure}
\centering
\caption{Caption}
\label{fig:my_label3}
\begin{tikzpicture}
\tkzKiviatDiagram[scale = 0.75,
                  label distance = .5cm,
                  radial = 5,
                  gap = 1,
                  lattice = 5]{A, B, C, D, E}
\tkzKiviatLine[thick,
               color = blue,
               mark = diamond,
               mark size = 5pt,
               ](4, 4, 4, 4, 4)
\tkzKiviatLine[thick,
               color = red,
               mark = square,
               mark size = 5pt](3, 3, 3, 3, 3)
\tkzKiviatLine[thick,
               color = green,
               mark = triangle,
               mark size = 5pt](3, 3, 3, 3, 3)
\tkzKiviatLine[thick,
               color = purple,
               mark = circle,
               mark size = 5pt](3, 3, 3, 3, 3)
\tkzKiviatLine[thick,
               color = blue,
               mark = +,
               dashed,
               mark size = 5pt](3, 3, 3, 3, 3)
\tkzKiviatLine[thick,
               color = red,
               mark = X,
               dashed,
               mark size = 5pt](3, 3, 3, 3, 3)
\tkzKiviatLine[thick,
               color = green,
               mark = star,
               dashed,
               mark size = 5pt](3, 3, 3, 3, 3)
\tkzKiviatLine[thick,
               color = purple,
               mark = circle,
               dashed,
               mark size = 5pt](3, 3, 3, 3, 3)
\tkzKiviatGrad[prefix = , unity = 1, suffix = \ \texteuro](1)
\end{tikzpicture}
\end{figure}

在此处输入图片描述

我想要用线条颜色制作图例并在标题上方做标记。

我怎样才能做到这一点?

答案1

用于tikz手动绘制图例(手动匹配颜色、线条样式等)。例如:

示例输出

前言,导入,加上定义 tkzKiviatDiagram:

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage} 
\usepackage{pgfplotstable} 
\usetikzlibrary{arrows}
\thispagestyle{empty}

\newcommand{\tkzKiviatDiagramFromDatFile}[1]{
\begin{tikzpicture}
\tkzKiviatDiagramFromFile[
        scale=.19,
        label distance=.5cm,
        gap     = 0.9,label space=5, 
        lattice = 10]{#1}
\tkzKiviatLineFromFile[thick,
                       color      = blue!80,
                       mark       = ball,
                       ball color = blue,
                       mark size  = 4pt,
                       fill       = blue!10]{#1}{1}
\tkzKiviatLineFromFile[thick,
                       color      = red,
                       mark       = ball,
                       ball color = red,
                       mark size  = 4pt,
                       fill       = green!20]{#1}{2}
\end{tikzpicture}}

定义图例:

\newcommand{\tkzKiviatLegend}[2]{\begin{tikzpicture}
    \draw[draw=black!05] (-0.1,-0.2) rectangle ++(5,0.5);
    \draw [thick, blue] (0,0) -- (0.5,0); 
    \node at (1.5,0) {#2};
    \draw [thick, red] (2.75,0) -- (3.25,0); 
    \node at (4,0) {#1};
\end{tikzpicture}}

具体用法:

\begin{document}

\tkzKiviatDiagramFromDatFile{table.dat}

\tkzKiviatLegend{Alpha}{Beta}

\end{document}

表.dat文件

column1     column2     column3
A           8.5         7
B           10          10
C           10          9.5
D           10          8
E           9           9

相关内容