LaTeX | TikZ | Spider Web | 如何在不四舍五入的情况下可视化小数?

LaTeX | TikZ | Spider Web | 如何在不四舍五入的情况下可视化小数?

我目前正在“建模”蜘蛛网图。我需要可视化像 8.95 这样的小数。在互联网上,我找到了一个非常好的解决方案来建模蜘蛛网图。不幸的是,所有小数都会四舍五入,这会导致图表中的可视化结果错误。

我尝试了两件事,但没有成功:

  • 将范围从 0-15(值 8.95)增加到 0-1500(值 895)
  • \begin{tikzpicture}[scale=1,x=15.0,y=15.0]

有人知道如何允许蜘蛛网中出现小数吗?提前谢谢!

这里是 MWE:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Spiderweb Diagram
%
% Author: Dominik Renzel
% Date; 2009-11-11
\documentclass{article}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage,floats]{preview}
\setlength\PreviewBorder{5pt}%
%%%>

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\newcommand{\D}{7} % number of dimensions (config option)
\newcommand{\U}{7} % number of scale units (config option)

\newdimen\R % maximal diagram radius (config option)
\R=3.5cm 
\newdimen\L % radius to put dimension labels (config option)
\L=4cm

\newcommand{\A}{360/\D} % calculated angle between dimension axes  

\begin{figure}[htbp]
 \centering

\begin{tikzpicture}[scale=1]
  \path (0:0cm) coordinate (O); % define coordinate for origin

  % draw the spiderweb
  \foreach \X in {1,...,\D}{
    \draw (\X*\A:0) -- (\X*\A:\R);
  }

  \foreach \Y in {0,...,\U}{
    \foreach \X in {1,...,\D}{
      \path (\X*\A:\Y*\R/\U) coordinate (D\X-\Y);
      \fill (D\X-\Y) circle (1pt);
    }
    \draw [opacity=0.3] (0:\Y*\R/\U) \foreach \X in {1,...,\D}{
        -- (\X*\A:\Y*\R/\U)
    } -- cycle;
  }

  % define labels for each dimension axis (names config option)
  \path (1*\A:\L) node (L1) {\tiny Security};
  \path (2*\A:\L) node (L2) {\tiny Content Quality};
  \path (3*\A:\L) node (L3) {\tiny Performance};
  \path (4*\A:\L) node (L4) {\tiny Stability};
  \path (5*\A:\L) node (L5) {\tiny Usability};
  \path (6*\A:\L) node (L6) {\tiny Generality};
  \path (7*\A:\L) node (L7) {\tiny Popularity};

  % Example Case (blue)
  \draw [color=blue,line width=1.5pt,opacity=0.5]
    (D1-1.5) --
    (D2-6.5) --
    (D3-4.2) --
    (D4-4.8) --
    (D5-3.6) --
    (D6-5.1) --
    (D7-2.3) -- cycle;

\end{tikzpicture}
\caption{Spiderweb Diagram (\D~Dimensions, \U-Notch Scale, 3 Samples)}
\label{fig:spiderweb}
\end{figure}

\end{document}

答案1

您可以通过使用calc库“混合”节点来实现您想要的效果。我在您的代码片段中添加了 3 个示例,其中两个节点设置在两个节点的中间,另一个节点贡献了 85%,这可能就是您所说的 4.85。

\documentclass{article}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage,floats]{preview}
\setlength\PreviewBorder{5pt}%
%%%>

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{calc}%<-added

\begin{document}

\newcommand{\D}{7} % number of dimensions (config option)
\newcommand{\U}{7} % number of scale units (config option)

\newdimen\R % maximal diagram radius (config option)
\R=3.5cm 
\newdimen\L % radius to put dimension labels (config option)
\L=4cm

\newcommand{\A}{360/\D} % calculated angle between dimension axes  

\begin{figure}[htbp]
 \centering

\begin{tikzpicture}[scale=1]
  \path (0:0cm) coordinate (O); % define coordinate for origin

  % draw the spiderweb
  \foreach \X in {1,...,\D}{
    \draw (\X*\A:0) -- (\X*\A:\R);
  }

  \foreach \Y in {0,...,\U}{
    \foreach \X in {1,...,\D}{
      \path (\X*\A:\Y*\R/\U) coordinate (D\X-\Y);
      \fill (D\X-\Y) circle (1pt);
    }
    \draw [opacity=0.3] (0:\Y*\R/\U) \foreach \X in {1,...,\D}{
        -- (\X*\A:\Y*\R/\U)
    } -- cycle;
  }

  % define labels for each dimension axis (names config option)
  \path (1*\A:\L) node (L1) {\tiny Security};
  \path (2*\A:\L) node (L2) {\tiny Content Quality};
  \path (3*\A:\L) node (L3) {\tiny Performance};
  \path (4*\A:\L) node (L4) {\tiny Stability};
  \path (5*\A:\L) node (L5) {\tiny Usability};
  \path (6*\A:\L) node (L6) {\tiny Generality};
  \path (7*\A:\L) node (L7) {\tiny Popularity};

  % Example Case (blue)
  \draw [color=blue,line width=1.5pt,opacity=0.5]
    ($(D1-1)!0.5!(D1-2)$) --
    (D2-6.5) --
    (D3-4.2) --
    ($(D4-4)!0.85!(D4-5)$) --
    (D5-3.6) --
    (D6-5.1) --
    (D7-2.3) -- cycle;

\end{tikzpicture}
\caption{Spiderweb Diagram (\D~Dimensions, \U-Notch Scale, 3 Samples)}
\label{fig:spiderweb}
\end{figure}

\end{document}

在此处输入图片描述

相关内容