2

Trying to adopt this answer approach, I didn't manage to get what I want of changing the style of the nodes near coords labels.

I would like to make this code poles={red, fill = blue, draw} work and accordingly change nodes near coords labels styles in addition to printing the correct labels (e.g. (-8,0) instead of 0).

\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=newest,
    poles/.style= { only marks, mark=x, mark size = 1ex, thick},
    nodes on coords/.style={
        nodes near coords,
        point meta = explicit symbolic,
        every node near coord/.style args={[#1]}%
        {
            anchor=south, label={[black,#1]\myangle:{\mylabel}}
        },
        visualization depends on={\thisrow{angle} \as \myangle},
        visualization depends on={value \thisrow{label} \as \mylabel},
    }
}

\usepackage{filecontents}
\begin{filecontents*}{poles.dat}
    Re      Im      label       angle
    -2      2       (-2,2)      270
    -2      -2      (-2,-2)     90
    -8      0       (-8,0)      60
\end{filecontents*}

\begin{document} 
\begin{tikzpicture}
    \begin{axis}
        \addplot[poles={red, fill = blue, draw}, nodes near coords]
        table {poles.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

2

This is an attempt of a partial answer. What it does is to allow you to add the labels to the nodes in the way I think you may have had in mind. In your code, you have a style nodes on coords, which you define but never use. More specifically, you use nodes near coords (rather than nodes on coords), which unless instructed otherwise, just places the \coordindex on top of the coordinates. Just trying to install nodes on coords lead to errors, so I decided to go step by step and just pasted the keys into the axis options after I modified them.

\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\tikzset{my node/.style={}}
\pgfplotsset{compat=newest,
    poles/.style= { only marks, mark=x, mark size = 1ex, thick},
}

\usepackage{filecontents}
\begin{filecontents*}{poles.dat}
    Re      Im      label       angle
    -2      2       (-2,2)      270
    -2      -2      (-2,-2)     90
    -8      0       (-8,0)      60
\end{filecontents*}

\begin{document} 
\begin{tikzpicture}
    \begin{axis}[point meta = explicit symbolic,
    visualization depends on={\thisrow{angle} \as \myangle},
        visualization depends on={value \thisrow{label} \as \mylabel},
        every node near coord/.append style={
            anchor=south, label={[black]\myangle:{\mylabel}}
        }]
        \addplot[poles={red, fill = blue, draw},nodes near coords]
        table {poles.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • Many thanks. I didn't realize that I have defined something I never used. – Diaa Nov 22 '18 at 5:51
  • Thanks to your answer and this one, I managed to do it right in the answer I posted. – Diaa Nov 22 '18 at 6:03
1

Thanks to @marmot's answer and this one, I think I figured out how to do it the right way.

\documentclass[border=1cm]{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=newest,
    poles/.style= { only marks, mark=x, mark size = 1ex, thick},
    point meta = explicit symbolic,
    visualization depends on={\thisrow{angle} \as \myangle},
    visualization depends on={value \thisrow{label} \as \mylabel},
    Label Style/.style args = {#1}{
        nodes near coords,
        every node near coord/.style = %
        {
            anchor=south, label={[#1]\myangle:{\mylabel}}
        },
    }
}

\usepackage{filecontents}
\begin{filecontents*}{poles.dat}
    Re      Im      label       angle
    -2      2       (-2,2)      270
    -2      -2      (-2,-2)     90
    -8      0       (-8,0)      60
\end{filecontents*}

\begin{document} 
\begin{tikzpicture}
    \begin{axis}
        \addplot[Label Style={blue,fill = gray!20},poles]
        table {poles.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

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.