0

I want to draw an asymptote to indicate the blue line to follow a certain path. However, the asymptote seems to shift as I adjust the height and width of the plot. I have tried to make everything respect the coordinate system. I can't seem to make everything obey the coordinate system of the plot. I want the arrow to indicate 60 degrees and the orange asymptote to make this 60 degrees.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{pgfplotstable}

\begin{document}
\begin{center}
  \pgfplotstableread[col sep=comma]{\detokenize{rlocus.dat}}\locustable
  \begin{tikzpicture}[baseline=(current axis.east)]
    \begin{axis}[
      xmin=-6.2,xmax=1.7,ymin=-3.2,ymax=3.2,
      minor tick num=1,
      xtick distance=1,
      ytick distance=1,
      grid=both,ticks=both
      ]
      \addplot[blue,thick] table[x index=0,y index=1]{\locustable};
      \draw[dashed, orange, ultra thick] (axis cs:-1.67,0) -- ++(60:4cm);
      \draw[->] (axis cs:-0.9, 0) arc (0:60:1cm) node[label={[label distance=0.01cm]0:$\SI{60}{\degree}$}] {};
    \end{axis}
  \end{tikzpicture}
\end{center}
\end{document}

enter image description here

I use some Matlab coordinates for the blue line. I extract these from the rlocus.dat file. The contents are listed here to make a MWE. I don't know how I can give the coordinates otherwise.

-0.78475,0
-0.7846,0.028256
-0.77227,0.25792
-0.74738,0.44939
-0.72046,0.59381
-0.6914,0.72116
-0.66012,0.84027
-0.62651,0.95522
-0.59046,1.0683
-0.55186,1.1811
-0.51059,1.2947
-0.46654,1.4098
-0.41957,1.5272
-0.36956,1.6475
-0.31636,1.771
-0.25984,1.8985
-0.19983,2.0302
-0.13617,2.1666
-0.068687,2.3081
0.0027904,2.4552
0.078457,2.6083
0.15851,2.7678
0.24317,2.9341
0.33264,3.1078
0.42717,3.2892
0.527,3.479
0.63239,3.6775
0.74362,3.8852
0.86097,4.1029
0.98474,4.3309
1.1153,4.5699
1.2529,4.8205
1.3979,5.0834
1.5507,5.3593
1.7118,5.6487
1.8814,5.9526
2.0601,6.2717
2.2484,6.6067
2.4466,6.9587
2.6553,7.3283
2.875,7.7167

EDIT:

Adding the answer ++(1cm, 0) to \draw[->] (axis cs:-0.9, 0) arc (0:60:1cm) node[label={[label distance=0.01cm]0:$\SI{60}{\degree}$}] {}; solves the issue in the MWE. But it doesn't solve it for the plot in Beamer. When I try to create a MWE in Beamer the problem is also fixed. However, in my full code the problem comes up. I have the following problem:

weird problem

And this is my code (not a MWE, because I can't make one which recreates the problem)

\begin{frame}{Verificatie}
    \begin{center}
        \pgfplotstableread[col sep=comma]{\detokenize{matlab/rlocus.dat}}\locustable
        \begin{tikzpicture}[baseline=(current axis.east)]
            \begin{axis}[width=\framewidth,height=7.5cm,
                xmin=-6.2,xmax=1.7,ymin=-2.2,ymax=2.2,
                axis equal,
                minor tick num=1,
                xtick distance=1,
                ytick distance=1,
                grid=both,ticks=both
                ]
                \addplot[only marks,thick,mark=x,color=red,mark size=5] coordinates {(0,0) (-2,0) (-3,0)};
                \addplot[blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.3 with {\arrow{>};}, mark=at position 0.7 with {\arrow{<};}}] coordinates {(0,0) (-2,0)};
                \addplot[blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.5 with {\arrow{<};}}] coordinates {(-7,0) (-3,0)};
                \addplot[blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.55 with {\arrow{>};}}] table[x index=0,y index=1]{\locustable};
                \addplot[blue,thick,postaction={decorate}, decoration={markings, mark=at position 0.55 with {\arrow{>};}}] table[x index=0,y expr=-\thisrowno{1}]{\locustable};
                \draw[<-, HRred] (axis cs:-1.67,0) -- ++(0cm,-2cm) node[below] {$s\approx-1.67$};
                \draw[->, HRred] (axis cs:-0.9, 0) -- ++(1cm, 0) arc (0:60:1cm) node[label={[label distance=0.01cm]0:$\SI{60}{\degree}$}] {};
                \only<2->
                {
                    \draw[dashed, orange, ultra thick] (axis cs:-1.67,0) -- ++(60:4cm);
                }
                \only<3->
                {
                    \draw[->, HRred] (axis cs:-0.9, 0) arc (0:180:1cm) node[label={[label distance=0.4cm]90:$\SI{180}{\degree}$}] {};
                }
                \only<4->
                {
                    \draw[dashed, orange, ultra thick] (axis cs:-1.67,0) -- ++(180:6cm);
                }
                \only<5->
                {
                    \draw[->, HRred] (axis cs:-0.9, 0) arc (0:300:1cm) node[label={[label distance=-2.2cm]0:$\SI{300}{\degree}$}] {};
                }
                \only<6->
                {
                    \draw[dashed, orange, ultra thick] (axis cs:-1.67,0) -- ++(300:6cm);
                }
            \end{axis}
        \end{tikzpicture}
    \end{center}
\end{frame}
2
  • 1
    Try the [axis equal] option of axis. Aug 2 at 11:51
  • Sorry, but if you "can't make [an MWE] which recreates the problem", then we can't help you. Give it another try, removing unnecessary stuff from your document step by step and checking if this changes your output. Creating an MWE is an important part of troubleshooting as it helps you locate the problem.
    – schtandard
    Aug 3 at 13:57

1 Answer 1

0

You just need to select the correct starting point for your arc. (For an arc with a radius of 1cm, that's 1cm to the right of its center, i.e. the start of the orange line.) I also uncluttered your MWE a bit.

\begin{filecontents}{rlocus.dat}
-0.78475,0
-0.7846,0.028256
-0.77227,0.25792
-0.74738,0.44939
-0.72046,0.59381
-0.6914,0.72116
-0.66012,0.84027
-0.62651,0.95522
-0.59046,1.0683
-0.55186,1.1811
-0.51059,1.2947
-0.46654,1.4098
-0.41957,1.5272
-0.36956,1.6475
-0.31636,1.771
-0.25984,1.8985
-0.19983,2.0302
-0.13617,2.1666
-0.068687,2.3081
0.0027904,2.4552
0.078457,2.6083
0.15851,2.7678
0.24317,2.9341
0.33264,3.1078
0.42717,3.2892
0.527,3.479
0.63239,3.6775
0.74362,3.8852
0.86097,4.1029
0.98474,4.3309
\end{filecontents}

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{pgfplotstable}

\begin{document}

\begin{center}
  \pgfplotstableread[col sep=comma]{\detokenize{rlocus.dat}}\locustable
  \begin{tikzpicture}
    \begin{axis}[
          axis equal,
          grid=both,
          ticks=both,
        ]
      \addplot [blue, thick] table [x index=0, y index=1] {\locustable};
      \draw [dashed, orange, ultra thick] (axis cs:-1.67,0) -- ++(60:4cm);
      \draw [->] (axis cs:-1.67, 0) ++(1cm, 0) arc (0:60:1cm) node [label={[label distance=0.01cm]0:\ang{60}}] {};
    \end{axis}
  \end{tikzpicture}
\end{center}

\end{document}

MWE output

Obviously, you would want to choose a radius fitting the rest of your plot nicely.

4
  • Thanks for your answer. It works with my MWE. However, I have boiled my example down. I use it in a Beamer environment, and now it doesn't work. When I add ++(1cm, 0) the angle is shifted all the way to the right and not in the plot itself Aug 2 at 14:59
  • @erwindenboer, at use with beamer try to ad option fragile to frame, i.e.: \begin{frame}[fragile].
    – Zarko
    Aug 2 at 15:12
  • @Zarko unfortunately, this has not solved the issue Aug 2 at 15:19
  • 1
    @erwindenboer, unfortunately we can only guess what is going on in your document. Please edit your question (or ask new one) where you provide MWE, which reproduce your problem.
    – Zarko
    Aug 2 at 17:51

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.