Kiviat 图表中的情节线隐藏了背景文本

Kiviat 图表中的情节线隐藏了背景文本

以下是 tkz-kiviat 包中的六边形 Kiviat 图表。虽然制作的图表足够漂亮,但图表的线条隐藏了背景文本。我还使用了 stackengine 和 adjustbox 包,将文本与箭头对齐到看起来漂亮的位置,但两个文本框“黑暗的”“维护良好”不会移动,但有一点成功。忽略图例设置,我需要背景文本清晰显示,没有线条切断它。以下是使用的代码:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multirow}
\usepackage{mathptmx}      
\usepackage{xcolor}
\usepackage{tikz,tkz-kiviat}
\usepackage{arrayjobx}
\usetikzlibrary{decorations.pathreplacing, arrows, fit,backgrounds,positioning,shapes,plotmarks,calc,decorations,angles,decorations.markings,intersections}

\usepackage[export]{adjustbox}
\usepackage{stackengine}
\tikzset{ultra thick,>=latex}
\makeatletter
\usepackage{trimspaces}
\def\trimspace#1{\trim@spaces@in{#1}}
\makeatother

\newarray\kivaxisitemlabels
\readarray{kivaxisitemlabels}{%
    &  \stackinset{c}{-0.75cm}{c}{-0.75cm}{Dark}{}  &\stackinset{c}{-2.25cm}{c}{-0.1cm}{\multirow{1}[3]{4.5cm}{\centering brownies/wheatish (fair looking)}}{}     &    whitish     &       &
    &\stackinset{c}{-1.45cm}{c}{-1.2cm}{strong}{}    &\stackinset{c}{-1.55cm}{c}{-0.9cm}{active}{}   & \stackinset{c}{-2.7cm}{c}{1cm}{weaklings}{} &       &
    &\stackinset{c}{0.9cm}{c}{0.5cm}{pessimistic}{}& \stackinset{c}{0.5cm}{c}{0.2cm}{\multirow{1}[3]{3cm}{\centering optimistic}}{}  & \stackinset{c}{0.4cm}{c}{0.5cm}{Realistic}{} & & 
    & \stackinset{c}{0.6cm}{c}{0.7cm}{\multirow{1}[1]{3cm}{\centering well motivated}}{}   & \stackinset{c}{0.5cm}{c}{0.9cm}{lethargic}{}  & demotivated &  &
    &\stackinset{c}{2.8cm}{c}{1.5cm}{Gigantic/Dwarfs}{}  &Normal & Average  &       &
    & \stackinset{c}{-0.8cm}{c}{0.2cm}{Handsome men }{}   &\stackinset{c}{-0.5cm}{c}{0.2cm}{Ugly boys}{} & \stackinset{c}{-0.5cm}{c}{0.2cm}{beautiful ladies}{}   &   &    }

\dataheight=5

\newcommand{\kivcurrentlabel}[2]{\checkkivaxisitemlabels(#1,#2)\trimspace\cachedata \cachedata}

\newcommand{\kivaxisnumbers}{6}
\newcommand{\kivcategorycounts}{{3,3,3,3,3,3}}
%\newcommand{\kivkumulativecategorycounts}{{0,2,5,9,13,17}}
%\newcommand{\kivcategorynames}{{1,2,10,20,30,100,200,300,400}}
\newcommand{\kivlcmcatcount}{3}

\newcommand{\kivlattice}{%
    \pgfmathsetmacro{\kivaxisangle}{360/\kivaxisnumbers}
    \foreach \x in {1,...,\kivaxisnumbers}
    {   \foreach \y in {1,...,\kivlcmcatcount}
        {   \pgfmathsetmacro{\kivaxisstep}{6/\kivlcmcatcount}
            \draw[help lines] (\kivaxisangle*\x:\y*\kivaxisstep) -- (\kivaxisangle*\x+\kivaxisangle:\y*\kivaxisstep);
        }
    }
    \foreach \x in {1,...,\kivaxisnumbers}
    {  \draw[ultra thick,-|] (0,0) -- (\kivaxisangle*\x:1.0cm); 
        \draw[ultra thick,->|] (0,0) -- (\kivaxisangle*\x:3.8cm);%-latex,line width=0.55mm
        \draw[ultra thick,->|] (0,0) -- (\kivaxisangle*\x:6.8cm);
        \pgfmathsetmacro{\kivaxissteps}{\kivcategorycounts[\x-1]}
        \pgfmathsetmacro{\kivaxisstep}{8.5/\kivcategorycounts[\x-1]}
        \foreach \y in {1,...,\kivaxissteps}
        {   %\pgfmathsetmacro{\kivhelper}{\kivkumulativecategorycounts[\x-1]}
            %\pgfmathtruncatemacro{\kivlabelname}{\kivcategorynames[\kivhelper+\y-1]}
            %\node[circle,fill=black,label=\x*\kivaxisangle+90:\kivlabelname,inner sep=1pt] at (\kivaxisangle*\x:\kivaxisstep*\y) {};
            \pgfmathtruncatemacro{\kivlabelnumber}{\y+1}            
            \node[label=\x*\kivaxisangle+60:\kivcurrentlabel{\x}{\kivlabelnumber}] at (\kivaxisangle*\x:\kivaxisstep*\y) {};
        }
    }
}


\newcommand{\LegendBox}[3][]{%
    \xdef\fitbox{}%
    \coordinate[#1] (LegendBox_anchor) at (#2) ;
    \foreach \col/\item [count=\hi from 0] in {#3} {
        \node[color = \col,draw,
        fill  = \col,
        shape=circle,
        inner sep=1.2ex,
        name=b\hi,
        ] at ([yshift=\hi*4 ex,xshift=3ex]LegendBox_anchor) {};
        \node[anchor=west,xshift=1ex] at (b\hi.east) (c\hi) {\item};
        \xdef\fitbox{\fitbox(c\hi)}
    }%
    \node [draw,fit=\fitbox(LegendBox_anchor)] {};
}
\makeatletter

\definecolor{A1}{RGB}{166, 206, 227}
\definecolor{B2}{RGB}{31, 120, 180}
\definecolor{C3}{RGB}{178, 223, 138}
\definecolor{D4}{RGB}{51, 160, 44}
\definecolor{E5}{RGB}{251, 154, 153}
\definecolor{F6}{RGB}{227, 26, 28}
\definecolor{G7}{RGB}{253, 191, 111}
\definecolor{H8}{RGB}{255, 127, 0}
\definecolor{I9}{RGB}{202, 178, 214}
\definecolor{J10}{RGB}{106, 61, 154}
\definecolor{K11}{RGB}{255, 255, 153}
\definecolor{L12}{RGB}{177, 89, 40} 
\definecolor{M13}{RGB}{140, 135, 32}
\definecolor{N14}{RGB}{231, 41, 138}
\definecolor{O15}{RGB}{135, 135, 135}
\definecolor{P16}{RGB}{53, 151, 143}
\begin{document}
    \begin{figure}[!h]
        
        
        \begin{adjustbox}{max totalsize={1.5\textwidth},center}
            
            \begin{tikzpicture}[label distance=.15cm]
                \begin{scope}
                    
                    
                    \tkzKiviatDiagram[font= \Large\bf, align=center, line width=1.15 mm, scale=1.25, label distance=.15cm,step=1.25,label space =1.25, gap= 1,lattice=10, lattice space=2]%
                    {People \parbox{1cm}{\centering distribution} ,Color \parbox{2cm}{\centering complexion},Physical \parbox{1cm}{\centering appearance},Nature,Phycology,Height}  
                    %   \draw (0,0)  node [midway] {\textbf{\Large GRMMC}};
                    \kivlattice
                    \tkzKiviatLine[line width=0.35mm,color=A1,mark={*},
                    mark size=3.5pt](0.95,3.15,0.95,3.15,3.15,0.95)
                    \tkzKiviatLine[line width=0.35mm,color=B2,mark={*},
                    mark size=3.5pt](5.55,3.35,5.95,3.35,5.55,3.7) 
                    \tkzKiviatLine[line width=0.35mm,color=C3,mark={*}, 
                    mark size=3.5pt](5.75,3.55,6.15,0.95,3.35,3.9)
                    \tkzKiviatLine[line width=0.35mm,color=D4,mark={*}, 
                    mark size=3.5pt](5.95,3.75,6.35,3.55,5.75,1.15)
                    \tkzKiviatLine[line width=0.35mm,color=E5,mark={*}, 
                    mark size=3.5pt](6.15,3.95,6.55,1.15,5.95,4.1)
                    \tkzKiviatLine[line width=0.35mm,color=F6,mark={*}, 
                    mark size=3.5pt](6.35,6.35,6.75,1.35,6.15,1.35)
                    \tkzKiviatLine[line width=0.35mm,color=G7,mark={*}, 
                    mark size=3.5pt](6.55,6.55,6.95,1.55,6.35,1.55)
                    \tkzKiviatLine[line width=0.35mm,color=H8,mark={*}, 
                    mark size=3.5pt](3.15,6.75,3.15,6.55,6.55,1.75)
                    \tkzKiviatLine[line width=0.35mm,color=I9,mark={*}, 
                    mark size=3.5pt](6.75,6.95,1.15,6.75,6.75,1.95)
                    \tkzKiviatLine[line width=0.35mm,color=J10,mark={*}, 
                    mark size=3.5pt](1.15,4.15,3.35,3.75,6.95,2.15)
                    \tkzKiviatLine[line width=0.35mm,color=K11,mark={*}, 
                    mark size=3.5pt](6.95,4.35,3.55,6.95,7.15,4.3)
                    \tkzKiviatLine[line width=0.35mm,color=L12,mark={*}, 
                    mark size=3.5pt](7.15,4.55,7.15,3.95,7.35,2.35)
                    \tkzKiviatLine[line width=0.35mm,color=M13,mark={*}, 
                    mark size=3.5pt](3.35,0.95,7.35,4.15,3.55,5.7)
                    \tkzKiviatLine[line width=0.35mm,color=N14,mark={*}, 
                    mark size=3.5pt](7.35,4.75,3.75,1.75,7.55,2.55)
                    \tkzKiviatLine[line width=0.35mm,color=O15,mark={*}, 
                    mark size=3.5pt](7.55,7.15,3.95,7.15,7.75,4.5)
                    \LegendBox[shift={(-25cm,-3cm)}]{current bounding box.south east}%
                    {A1/ 1,
                        B2/ 2,
                        C3/ 3 } 
                    \LegendBox[shift={(-20cm,0.4cm)}]{current bounding box.south east}%
                    {D4/ 4,
                        E5/ 5,
                        F6/ 6 }
                    \LegendBox[shift={(-15cm,0.42cm)}]{current bounding box.south east}%
                    {G7/ 7,
                        H8/ 8,%\cite{Guo2020}ZHOU201993
                        I9/ 9 }
                    \LegendBox[shift={(-10cm,0.44cm)}]{current bounding box.south east}%
                    {J10/ 10,
                        K11/ 11,
                        L12/ 12 }
                    \LegendBox[shift={(-5cm,0.46cm)}]{current bounding box.south east}%
                    {M13/ 13,
                        N14/ 14,
                        O15/ 15 }
                \end{scope}
            \end{tikzpicture}
            
        \end{adjustbox}
        \caption{Conclusive findings from the literature after a hasty uncontrolled view  }
        \label{Fig_fig:16New}
    \end{figure}
\end{document}

输出:

答案1

TikZ 按照您在代码中提供的顺序绘制元素(有一些例外,特别是 tikzlibrary backgrounds)。

因此,如果您希望情节标记位于箭头线的顶部,并且文本标签位于所有内容的顶部,那么您应该首先放置箭头线的代码,然后放置情节标记的代码,然后放置文本标签的代码。

箭头线和文本标签在\kivlattice宏中一起绘制。因此,要单独绘制它们,您需要将宏分成两部分,这需要使用相同的 for 循环两次。然后您可以在\tkzKiviatLine格子的两个部分之间绘制标记。

代码(片段,不重复问题中的完整 MWE):

\newcommand{\kivarrowsonly}{%
\pgfmathsetmacro{\kivaxisangle}{360/\kivaxisnumbers}
    \foreach \x in {1,...,\kivaxisnumbers}
    {   \foreach \y in {1,...,\kivlcmcatcount}
        {   \pgfmathsetmacro{\kivaxisstep}{6/\kivlcmcatcount}
            \draw[help lines] (\kivaxisangle*\x:\y*\kivaxisstep) -- (\kivaxisangle*\x+\kivaxisangle:\y*\kivaxisstep);
        }
    }
    \foreach \x in {1,...,\kivaxisnumbers}
    {  \draw[ultra thick,-|] (0,0) -- (\kivaxisangle*\x:1.0cm); 
        \draw[ultra thick,->|] (0,0) -- (\kivaxisangle*\x:3.8cm);%-latex,line width=0.55mm
        \draw[ultra thick,->|] (0,0) -- (\kivaxisangle*\x:6.8cm);
     }
}
\newcommand{\kivlattice}{%
    \pgfmathsetmacro{\kivaxisangle}{360/\kivaxisnumbers}
    \foreach \x in {1,...,\kivaxisnumbers}
    {   \pgfmathsetmacro{\kivaxissteps}{\kivcategorycounts[\x-1]}
        \pgfmathsetmacro{\kivaxisstep}{8.5/\kivcategorycounts[\x-1]}
        \foreach \y in {1,...,\kivaxissteps}
        {   %\pgfmathsetmacro{\kivhelper}{\kivkumulativecategorycounts[\x-1]}
            %\pgfmathtruncatemacro{\kivlabelname}{\kivcategorynames[\kivhelper+\y-1]}
            %\node[circle,fill=black,label=\x*\kivaxisangle+90:\kivlabelname,inner sep=1pt] at (\kivaxisangle*\x:\kivaxisstep*\y) {};
            \pgfmathtruncatemacro{\kivlabelnumber}{\y+1}            
            \node[label=\x*\kivaxisangle+60:\kivcurrentlabel{\x}{\kivlabelnumber}] at (\kivaxisangle*\x:\kivaxisstep*\y) {};
        }
    }
}
%%%%%% [lots of code in between] %%%%%%
\tkzKiviatDiagram[font= \Large\bf, align=center, line width=1.15 mm, scale=1.25, label distance=.15cm,step=1.25,label space =1.25, gap= 1,lattice=10, lattice space=2]%
                    {People \parbox{1cm}{\centering distribution} ,Color \parbox{2cm}{\centering complexion},Physical \parbox{1cm}{\centering appearance},Nature,Phycology,Height}  
                    %   \draw (0,0)  node [midway] {\textbf{\Large GRMMC}};
                    \kivarrowsonly
                    \tkzKiviatLine[line width=0.35mm,color=A1,mark={*},
                    mark size=3.5pt](0.95,3.15,0.95,3.15,3.15,0.95)
%%%%%% more \tkzKiviatLine statements here %%%%%%                    
                    \tkzKiviatLine[line width=0.35mm,color=O15,mark={*}, 
                    mark size=3.5pt](7.55,7.15,3.95,7.15,7.75,4.5)
                    \kivlattice
                    \LegendBox[shift={(-25cm,-3cm)}]{current bounding box.south east}%
                    {A1/ 1,
                        B2/ 2,
                        C3/ 3 } 
%%%%%% [...] %%%%%%

结果:

在此处输入图片描述

相关内容