TIKZ - 自动转换文本

TIKZ - 自动转换文本

我有一张使用以下代码自动创建的图片。但是,我不知道如何将“标签”Q1、Q2 和 Q3 自动旋转为与圆心成矩形。

在此处输入图片描述

\documentclass[a4paper,10pt]{article} 
\usepackage{tikz,readarray,xcolor}

%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define the colours
%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{MediaFocusBlue}{HTML}{66ffcc}
\definecolor{MediaFocusYellow}{HTML}{ffff99}
\definecolor{MediaFocusOrange}{HTML}{ff9933}


\begin{filecontents*}{Daten.csv}
Zurich;Q4;Q3;Q2;Q1
Print Ads;17;6;12;7
TV Ads;14;17;1;19
OOH Ads;-;6;7;6
Radio Ads;7;18;5;13
Cinema Ads;1;7;16;18
Internet Ads;7;4;13;20
SEO;9;14;6;8
Web;17;5;5;19
Influencer;3;1;9;10
Social Media;12;2;11;8
Online News;14;2;1;19
Print News;12;8;10;8
\end{filecontents*}

\usetikzlibrary{external}
\begin{document}
\readarraysepchar{;}
\readdef{Daten.csv}\myrecorddata
\readarray\myrecorddata\twoD[-,\ncols]

\begin{figure}
\begin{center}
\begin{tikzpicture}
\foreach\i in {2,...,\twoDROWS}{
\if\twoD[\i,2]-
    \def\colour{white}
    \def\linecolour{black}
\else
    \ifcase\twoD[\i,2]
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %1
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %2
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %3
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %4
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %5
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %6
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
    \or %7
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %8
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %9
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %10
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %11
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %12
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %13
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \else
            \def\colour{MediaFocusOrange}
            \def\linecolour{white}
    \fi 
\fi 
    \coordinate (C\i) at ( \i  * 30  + 30:5);
    \fill[\colour!80,draw=\linecolour]   ( C\i ) circle (1);
    \node (B\i) [align=center,above of=C\i,node distance=0.3cm,text     width=1.5cm] {\twoD[\i,1]};
    \node (W\i) [align=center,below of=C\i,node distance=0.4cm] {\twoD[\i,2]};
}

\foreach\j in {3,...,\twoDCOLS}{
    \draw (0,0) circle (4 + \j * 0.9);
    \foreach\k in {2,...,\twoDROWS}{
        \coordinate (P\k) at (\k *30 + 30: 4 + \j * 0.9);
        \fill[gray!80]   ( P\k ) circle (0.3);
        \node (T\k) [align=center] at (P\k) {\twoD[\k,\j]};
        \node (Z\k) [align=center,fill=white] at (\k *30 + 15: 4 + \j * 0.9) {\twoD[1,\j]};
    }       
}
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

答案1

我不太确定你所说的到圆心的“矩形”到底是什么意思。

我添加了一个rotate=\k*30-75键,它可以旋转Q1Q2Q3

        \node (Z\k) [align=center,fill=white,rotate=\k*30-75] at (\k *30 + 15: 4 + \j * 0.9) {\twoD[1,\j]};

在此处输入图片描述

完整代码:

\documentclass[a4paper,10pt]{article}
\usepackage{fullpage}
\usepackage{tikz,readarray,xcolor}

%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define the colours
%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{MediaFocusBlue}{HTML}{66ffcc}
\definecolor{MediaFocusYellow}{HTML}{ffff99}
\definecolor{MediaFocusOrange}{HTML}{ff9933}


\begin{filecontents*}{Daten.csv}
Zurich;Q4;Q3;Q2;Q1
Print Ads;17;6;12;7
TV Ads;14;17;1;19
OOH Ads;-;6;7;6
Radio Ads;7;18;5;13
Cinema Ads;1;7;16;18
Internet Ads;7;4;13;20
SEO;9;14;6;8
Web;17;5;5;19
Influencer;3;1;9;10
Social Media;12;2;11;8
Online News;14;2;1;19
Print News;12;8;10;8
\end{filecontents*}

\usetikzlibrary{external}
\begin{document}
\readarraysepchar{;}
\readdef{Daten.csv}\myrecorddata
\readarray\myrecorddata\twoD[-,\ncols]

\begin{figure}
\begin{center}
\begin{tikzpicture}
\foreach\i in {2,...,\twoDROWS}{
\if\twoD[\i,2]-
    \def\colour{white}
    \def\linecolour{black}
\else
    \ifcase\twoD[\i,2]
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %1
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %2
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %3
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %4
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %5
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %6
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
    \or %7
            \def\colour{MediaFocusBlue}
            \def\linecolour{white}
        \or %8
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %9
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %10
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %11
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %12
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \or %13
            \def\colour{MediaFocusYellow}
            \def\linecolour{white}
        \else
            \def\colour{MediaFocusOrange}
            \def\linecolour{white}
    \fi
\fi
    \coordinate (C\i) at ( \i  * 30  + 30:5);
    \fill[\colour!80,draw=\linecolour]   ( C\i ) circle (1);
    \node (B\i) [align=center,above of=C\i,node distance=0.3cm,text     width=1.5cm] {\twoD[\i,1]};
    \node (W\i) [align=center,below of=C\i,node distance=0.4cm] {\twoD[\i,2]};
}

\foreach\j in {3,...,\twoDCOLS}{
    \draw (0,0) circle (4 + \j * 0.9);
    \foreach\k in {2,...,\twoDROWS}{
        \coordinate (P\k) at (\k *30 + 30: 4 + \j * 0.9);
        \fill[gray!80]   ( P\k ) circle (0.3);
        \node (T\k) [align=center] at (P\k) {\twoD[\k,\j]};
        \node (Z\k) [align=center,fill=white,rotate=\k*30-75] at (\k *30 + 15: 4 + \j * 0.9) {\twoD[1,\j]};
    }
}
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

相关内容