11

I would like to draw "stealth" arrows in place of the "0" labels along the trajectory in the phase portrait pictured below. I decided to draw the trajectory using the contour functionality of Pgfplots. So far, I managed to set the inner separation of the labels to zero, but I am having trouble figuring out how to change the label text. Do you have any ideas?

enter image description here

Here is the code I used to generate the plot:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    title={Phase portrait of Van der Pol oscillator.},
    domain=-2:2,
    xmin=-2,
    xmax=2,
    ymin=-2,
    ymax=2,
    view={0}{90},
    axis background/.style={fill=white}
]

\addplot3[
    contour prepared =
    {
        contour label style = {
            inner sep = 0pt
        },
        draw color = black,
        label distance = 140pt,
        handler/.style = /tikz/smooth
    }
] table {
1   1   0
1.06298 0.924071    0
1.12034 0.837528    0
1.1715  0.742761    0
1.21604 0.642327    0
1.2537  0.53874 0
1.28439 0.434294    0
1.30815 0.330936    0
1.32515 0.230198    0
1.33561 0.133173    0
1.33981 0.0405447   0
1.33807 -0.0473723  0
1.33071 -0.130566   0
1.31803 -0.209266   0
1.30032 -0.283883   0
1.27781 -0.354957   0
1.25071 -0.423121   0
1.21919 -0.489065   0
1.18336 -0.553523   0
1.14327 -0.617253   0
1.09894 -0.681037   0
1.05031 -0.745674   0
0.997309    -0.811985   0
0.939765    -0.880811   0
0.877471    -0.953012   0
0.81016 -1.02946    0
0.737503    -1.11104    0
0.659117    -1.19857    0
0.574566    -1.2928 0
0.483372    -1.39432    0
0.385033    -1.50335    0
0.279056    -1.61961    0
0.165004    -1.742  0
0.0425688   -1.86824    0
-0.0883296  -1.99446    0
-0.227417   -2.1148 0
-0.37392    -2.22123    0
-0.526427   -2.30376    0
-0.68279    -2.35129    0
-0.84013    -2.35325    0
-0.994979   -2.30182    0
-1.14358    -2.19409    0
-1.28228    -2.03341    0
-1.40797    -1.82915    0
-1.5184 -1.59496    0
-1.61235    -1.34614    0
-1.68956    -1.09692    0
-1.75062    -0.858681   0
-1.79667    -0.639141   0
-1.82921    -0.442463   0
-1.84984    -0.269927   0
-1.86016    -0.120777   0
-1.86162    0.00698576  0
-1.85553    0.115975    0
-1.84301    0.208983    0
-1.82497    0.288714    0
-1.80219    0.357639    0
-1.77525    0.417936    0
-1.74466    0.471483    0
-1.71076    0.519882    0
-1.67385    0.56449 0
-1.6341 0.606463    0
-1.59164    0.646794    0
-1.54654    0.686352    0
-1.49881    0.725909    0
-1.44841    0.766178    0
-1.39527    0.807829    0
-1.33925    0.85152 0
-1.2802 0.89791 0
-1.21788    0.947684    0
-1.15205    1.00156 0
-1.0824 1.06031 0
-1.00855    1.12475 0
-0.930078   1.19577 0
-0.846509   1.27428 0
-0.757294   1.36121 0
-0.661824   1.45744 0
-0.559443   1.56366 0
-0.449463   1.68024 0
-0.331198   1.80687 0
-0.204031   1.94227 0
-0.0675019  2.08357 0
0.0785556   2.22577 0
0.233841    2.3611  0
0.397387    2.47881 0
0.567366    2.5655  0
0.740977    2.60659 0
0.914493    2.58894 0
1.08351 2.50416 0
1.24344 2.35155 0
1.39009 2.13913 0
1.52018 1.88231 0
1.6317  1.60044 0
1.72397 1.31283 0
1.79745 1.03554 0
1.85344 0.779751    0
1.89372 0.551697    0
1.92029 0.353461    0
1.93511 0.184222    0
1.94001 0.0414127   0
1.93657 -0.0783631  0
};

\addplot3[
    color=black!30!white,
    quiver={
        u={y},
        v={0 - x + y * (1 - x^2)},
        scale arrows=0.1
    },
    -stealth,
    samples=20
]{0};

\end{axis}
\end{tikzpicture}
\end{document}

Thanks for your help!

11

I wouldn't use a contour in this case, but a normal plot, with the arrows placed using a decoration:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    title={Phase portrait of Van der Pol oscillator.},
    domain=-2:2,
    xmin=-2,
    xmax=2,
    ymin=-2,
    ymax=2,
    view={0}{90},
    axis background/.style={fill=white}
]

\addplot3[
    color=black!30!white,
    quiver={
        u={y},
        v={0 - x + y * (1 - x^2)},
        scale arrows=0.1
    },
    -stealth,
    samples=20
]{0};

\addplot3[decoration={
    markings,
    mark=between positions 0.1 and 1 step 8em with {\arrow [scale=1.5]{stealth}}
    }, postaction=decorate] table {
1   1   0
1.06298 0.924071    0
1.12034 0.837528    0
1.1715  0.742761    0
1.21604 0.642327    0
1.2537  0.53874 0
1.28439 0.434294    0
1.30815 0.330936    0
1.32515 0.230198    0
1.33561 0.133173    0
1.33981 0.0405447   0
1.33807 -0.0473723  0
1.33071 -0.130566   0
1.31803 -0.209266   0
1.30032 -0.283883   0
1.27781 -0.354957   0
1.25071 -0.423121   0
1.21919 -0.489065   0
1.18336 -0.553523   0
1.14327 -0.617253   0
1.09894 -0.681037   0
1.05031 -0.745674   0
0.997309    -0.811985   0
0.939765    -0.880811   0
0.877471    -0.953012   0
0.81016 -1.02946    0
0.737503    -1.11104    0
0.659117    -1.19857    0
0.574566    -1.2928 0
0.483372    -1.39432    0
0.385033    -1.50335    0
0.279056    -1.61961    0
0.165004    -1.742  0
0.0425688   -1.86824    0
-0.0883296  -1.99446    0
-0.227417   -2.1148 0
-0.37392    -2.22123    0
-0.526427   -2.30376    0
-0.68279    -2.35129    0
-0.84013    -2.35325    0
-0.994979   -2.30182    0
-1.14358    -2.19409    0
-1.28228    -2.03341    0
-1.40797    -1.82915    0
-1.5184 -1.59496    0
-1.61235    -1.34614    0
-1.68956    -1.09692    0
-1.75062    -0.858681   0
-1.79667    -0.639141   0
-1.82921    -0.442463   0
-1.84984    -0.269927   0
-1.86016    -0.120777   0
-1.86162    0.00698576  0
-1.85553    0.115975    0
-1.84301    0.208983    0
-1.82497    0.288714    0
-1.80219    0.357639    0
-1.77525    0.417936    0
-1.74466    0.471483    0
-1.71076    0.519882    0
-1.67385    0.56449 0
-1.6341 0.606463    0
-1.59164    0.646794    0
-1.54654    0.686352    0
-1.49881    0.725909    0
-1.44841    0.766178    0
-1.39527    0.807829    0
-1.33925    0.85152 0
-1.2802 0.89791 0
-1.21788    0.947684    0
-1.15205    1.00156 0
-1.0824 1.06031 0
-1.00855    1.12475 0
-0.930078   1.19577 0
-0.846509   1.27428 0
-0.757294   1.36121 0
-0.661824   1.45744 0
-0.559443   1.56366 0
-0.449463   1.68024 0
-0.331198   1.80687 0
-0.204031   1.94227 0
-0.0675019  2.08357 0
0.0785556   2.22577 0
0.233841    2.3611  0
0.397387    2.47881 0
0.567366    2.5655  0
0.740977    2.60659 0
0.914493    2.58894 0
1.08351 2.50416 0
1.24344 2.35155 0
1.39009 2.13913 0
1.52018 1.88231 0
1.6317  1.60044 0
1.72397 1.31283 0
1.79745 1.03554 0
1.85344 0.779751    0
1.89372 0.551697    0
1.92029 0.353461    0
1.93511 0.184222    0
1.94001 0.0414127   0
1.93657 -0.0783631  0
};



\end{axis}
\end{tikzpicture}
\end{document}
  • Thanks for your answer; it works perfectly! However, I noticed a minor problem: sometimes, the gray arrows and lines are drawn over the black ones. Is there any way to ensure that the black curve and arrows are drawn over everything else? Changing the z-coordinates of the points in the table did not help. – void-pointer May 11 '13 at 14:58
  • 1
    @void-pointer: Sure, just swap the order of the \addplot commands (you could also use layers, but that would be a little more complicated). – Jake May 11 '13 at 15:00

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.