0

here's my MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{amsmath}
\pgfplotsset{compat=1.12}

\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\begin{axis}[
    width=0.6\textwidth,
    view={0}{90},
    domain=0:2*pi+0.5,
    y domain=0:2*pi+0.5,
    xmax=2*pi+1, ymax=2*pi+1,
    samples=15,
    axis equal image,
    axis lines = center,
    xtick = {0,3.14,6.28},
    ytick = {0,3.14,6.28},
    xticklabels = {0,$\pi$,$2\pi$},
    yticklabels = {0,$\pi$,$2\pi$}
]
\addplot3 [blue, quiver={u={1}, v={sin(deg(\x))^2}, scale arrows=0.3, every arrow/.append style={-latex}}] (x,y,0);
\addplot [thick, red] {2-sin(deg(\x))*cos(deg(\x))/2+\x/2};
\end{axis}
\end{tikzpicture}
    \caption{Retningsfelt (blå) for $\dfrac{d  x}{d  t}=\sin^2(t)$, med løsningskurve (rød) gennem $x(0)=2$.}
  \label{fig:bvp1}
\end{figure}
\end{document}

I get the error message

Package pgfplots Warning: Axis range for z is approximately empty; enlarging it (it is [0.0;0.0]) on input line 29.

I've tried some of the fixes I read on other posts, but I haven't seemed to make any of it work.

5
  • On my computer, it runs without error. Can you try adding restrict z to domain=0:0, to your axis options ?
    – BambOo
    Commented Sep 20, 2018 at 8:58
  • Didn't work - but weird... I'm compiling in ShareLatex using pdfLaTeX.
    – Johan
    Commented Sep 20, 2018 at 9:10
  • 1
    Just tested on overleaf, and it works too...
    – BambOo
    Commented Sep 20, 2018 at 9:33
  • Well that's just weird as hell then ...
    – Johan
    Commented Sep 20, 2018 at 9:37
  • 1
    Please see my proposition below and tell me if this helps
    – BambOo
    Commented Sep 20, 2018 at 11:36

1 Answer 1

1

I have some doubts regarding the syntax you use. Both seem to work, but the syntax proposed in the pgfplots manual differs from what you use.

For complimentary information, have a look at section 4.5.8 Quiver plots p 90 of the pgfplots manual.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{amsmath}
\pgfplotsset{compat=1.12}

\begin{document}

Original code
\begin{tikzpicture}
\begin{axis}[
    width=0.6\textwidth,
    view={0}{90},
    domain=0:2*pi+0.5,
    y domain=0:2*pi+0.5,
    xmax=2*pi+1, ymax=2*pi+1,
    samples=15,
    axis equal image,
    axis lines = center,
    xtick = {0,3.14,6.28},
    ytick = {0,3.14,6.28},
    xticklabels = {0,$\pi$,$2\pi$},
    yticklabels = {0,$\pi$,$2\pi$}
]
\addplot3 [blue, quiver={u={1}, v={sin(deg(\x))^2}, scale arrows=0.3, every arrow/.append style={-latex}}] (x,y,0);
\addplot [thick, red] {2-sin(deg(\x))*cos(deg(\x))/2+\x/2};
\end{axis}
\end{tikzpicture}

Modified code
\begin{tikzpicture}
\begin{axis}[
    width=0.6\textwidth,
    view={0}{90},
    domain=0:2*pi+0.5,
    y domain=0:2*pi+0.5,
    xmax=2*pi+1, ymax=2*pi+1,
    samples=15,
    axis equal image,
    axis lines = center,
    xtick = {0,3.14,6.28},
    ytick = {0,3.14,6.28},
    xticklabels = {0,$\pi$,$2\pi$},
    yticklabels = {0,$\pi$,$2\pi$}
]
\addplot3 [blue, quiver={u={1}, v={sin(deg(x))^2}, scale arrows=0.3, every arrow/.append style={-latex}}] {x};
\addplot [thick, red] {2-sin(deg(x))*cos(deg(x))/2+x/2};
\end{axis}
\end{tikzpicture}


\end{document}

enter image description here

1
  • "doubts regarding the syntax you use" - would you please point the differences in syntax? Commented May 12, 2023 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .