2

I am new with pgfplot and I need to recreate this graph(but not such ugly). I hardly imagine how to make it point by point but my main problem is these vertical dashed lines on some points. enter image description here

Here is my MWE. How to add labels for points? How can I add these vertical lines for some points like picture above?

\documentclass[12pt,a4paper]{letter}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[grid=both,
    width=\linewidth,
    xmode=log,
    ymin=-140,
    ymax=90,
    log basis x={10},
    xlabel={$ \omega $ rad/s},
    x label style={at={(axis description cs:0.95,-0.01)}}
    ]
    \addplot[
    color=blue,
    mark=*
    ]
    coordinates {
        (-1,80)(0.1,60)(0.4,40)(1,20)(4,-80)(8,-140)
    };
    \legend{}
    \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

1
  • To add labels for points you can use nodes near coords – Salim Bou Oct 17 '16 at 18:37
5

You mean something like that?

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.3,
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            xmode=log,
            ymin=-140,
            ymax=90,
            xlabel={$\omega$ / rad/s},
            x label style={
                at={(axis description cs:0.95,-0.05)}},
            grid=both,
            % turn of clipping so also the stuff outside the plot is shown
            clip=false,
        ]
            \addplot[
                color=blue,
                mark=*
            ] coordinates {
                (-1,80)(0.1,60)(0.4,40)(1,20)(4,-80)(8,-140)
            }
            % add some nodes to the plot
                node [below=1ex,pos=0.1,font=\small] {$-40/\pi$}
                node [below=2ex,pos=0.3,font=\small] {$-60/\pi$}
            ;

            % add the extra tick labels with a loop
            \pgfplotsforeachungrouped \x/\i in {
                0.4/1,
                4/2%
            }{
                \edef\temp{\noexpand%
                \draw [
                    % use same color as the grid ...
                    black!25,
                    % ... but make it dashed
                    dashed,
                    % in case these lines already are laying on a grid line
                    % first draw a white line on which then the dashed line
                    % is drawn
                    preaction={
                        draw=white,
                    },
                ]
                    % give x coordinates as normal x coordinates ans
                    % y as relative coordinates, so they are independent on
                    % ymin and max. This also allows to easily draw a bit
                    % more down than the normal tick labels
                    ({axis cs:\x,0} |- {rel axis cs:0,1}) --
                        ({axis cs:\x,0} |- {rel axis cs:0,-0.1})
                            node [below,text=black] {$\omega_\i = \x$};
                }\temp
            }
        \end{axis}
    \end{tikzpicture}
\end{document}

image showing the result of above code

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.