3

I've a picture that is automatically created with below code. However, I can't find how to turn the "labels" Q1, Q2 and Q3 automatically to be rectangular to the center of the circle.

enter image description here

\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
    Instead of turning, I would rather keep one Q1, Q2, and Q3 and remove the other 3 * 11 labels because of too much distracting redundancy. – Heiko Oberdiek Mar 17 '18 at 18:53
  • I am thinking about how to do this. My current idea is to turn the circles by 15° and having the Q1, Q2, Q3 at every quarter of the figure. That way, it is symmetric. – Shade Mar 18 '18 at 13:15
6

I'm not sure precisely what you mean by "rectangular" to the center of the circle.

I added a rotate=\k*30-75 key to and it rotates the Q1, Q2, and Q3.

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

enter image description here

Full code:

\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}
  • Very nice answer. +1. – Sebastiano Mar 17 '18 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.