1

Situation and Problem

This question is a follow-up and based on marmots answers to this question and this. The general situation is described there.

Now I want to simplify input. More specifically I would prefer not to give an angle, but a value in [-1,1] that maps to the acutal angle (as the final diagram might differ). This formula should work:

angular_position = class*\SegmentAngleWidth+\SegmentAngleWidth/2*(1+angpos)

Question

How to use a calculated x-position in a pgfplots with information from table-columns?

I have tried to use an answer to a similar problem, but could not get it to work.

MWE
\documentclass[border=3mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.15} 
\usepgfplotslibrary{polar}

\usepackage{filecontents}
\begin{filecontents*}{radar_calc_test.csv}
    name,class,radius,angpos
    a, 1, 9,  1
    b, 1, 3,  0.1
    c, 2, 6,  -1
    d, 1, 6,  -0.5
    e, 2, 8,  -0.3
    f, 2, 5,  0.2
    g, 2, 2,  0.8
    h, 1, 8,  -0.4
    i, 2, 9,  0
    j, 2, 7,  0
    v, 2, 2,  -0.7
    w, 1, 4,  -0.7
    x, 1, 7,  0.5
    y, 1, 2,  0.5
    z, 1, 1,  -0.5
\end{filecontents*}
% name, angular segment, radius
% angular_position_in_segment = class*\SegmentAngleWidth+\SegmentAngleWidth/2*(1+angpos)


\begin{document}

\def\SegmentAngleWidth{90}

\pgfplotstableset{% global config, for example in the preamble
    create on use/angular_position/.style={
        create col/expr={
            \thisrow{class}*\SegmentAngleWidth+\SegmentAngleWidth/2*(1+\thisrow{angpos})
        }
    }
}

\begin{tikzpicture}
    \begin{polaraxis}[
        visualization depends on={value \thisrow{name} \as \labelname}
    ]
        \addplot[
            scatter/classes={
                1={
                    mark                = text,
                    text mark as node   = true,
                    text mark           = \labelname,
                    text mark style     = {
                        circle,
                        blue,
                        draw
                    }
                },
                2={
                    mark                = text,
                    text mark as node   = true,
                    text mark           = \labelname,
                    text mark style     = {
                        red,
                        draw
                    }
                }
            },
            scatter,
            draw        = none,
            point meta  = explicit symbolic
        ] table[
            x       = angular_position, %"angpos" would work
            y       = radius,
            col sep = comma,
            meta    = class
        ] {radar_calc_test.csv};
    \end{polaraxis}
\end{tikzpicture}
\end{document}
2
  • Does your code create the output shown on your machine? On mine, it doesn't. (I also think you need to add create on use/angular_position to the options of the table, the above only defines the style, but does not apply it automatically to all tables.) – user121799 Jun 16 '19 at 17:48
  • @marmot, no. You'd have to exchange angular_position with angpos to get the output. I just wanted the closest thing that still compiled. In the meantime, I have found this answer that uses the same starting point. Yet, I can not see the difference or my error. – BadAtLaTeXProgramming Jun 16 '19 at 20:59

Your Answer

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

Browse other questions tagged or ask your own question.