1

The x tick labels in my figure disappear when I change one option in my LaTeX code.

This is my original code:

\documentclass{article}

\usepackage{fp}
\usepackage{pgfplots}

\pgfplotsset{width=15cm, compat=1.12}

\newcommand{\tG}{20}
\newcommand{\xI}{150}
\newcommand{\vL}{16.67}
\newcommand{\aA}{1.2}
\newcommand{\aB}{1.5}

\FPeval\vResult{\aB * \vL / (\aA + \aB)}
\newcommand{\vS}{\vResult}

\FPeval\xResult{\xI - (\vS)^2 / (2*\aB)}
\newcommand{\xS}{\xResult}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xlabel=$x_G$,ylabel=$v_G$,
domain=0:\xI,
y domain=0:20,
enlargelimits=false,
view={0}{90}]

\addplot3[surf,shader=interp]
{\tG - x/\vL + (\vL-y)^2/(2*\aA*\vL)};

\addplot3[contour gnuplot={draw color=black},thick]
{\tG - x/\vL + (\vL-y)^2/(2*\aA*\vL)};

\addplot3[black,
quiver={
    u={-1/\vL},
    v={-(\vL-y)/(\aA*\vL)},
    scale arrows=2,
},
-stealth,samples=15]
{\tG - x/\vL + (\vL-y)^2/(2*\aA*\vL)};

\addplot[red]
{\vL};

\addplot[red,samples=101]
{sqrt( (\xI - x)*(2*\aB) )};

\addplot[mark=x, mark size=5] coordinates {(\xS,\vS)} node[label={[label distance=0cm]45:{$(x^*,v^*)$}}]{} ;

\end{axis}
\end{tikzpicture}

\end{document}

and my original output

enter image description here

When I change the code by adding one line, so that it becomes

\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
...

this is the result

enter image description here

As you can see, the x axis tick labels have disappeared and I don't know why. I think it may have something to do with the fact I am using 3D plots. Any ideas how I can get my labels back (and ensure the x axis is positioned at y=0)?

  • 5
    Welcome to TeX.SE. What happend if you re-run pfdlatex again? Also, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Apr 20 '17 at 5:20
  • In particular, your code has a lot of custom macros. At the very least add the definition of those, so that we don't have to figure out which numbers are appropriate. – Torbjørn T. Apr 21 '17 at 12:11
  • @JohnKormylo axis x line=middle means that the x-axis is placed where y=0, not in the literal middle. As the surface plot stops at y=0, the ticklabels should be visible below it. – Torbjørn T. Apr 23 '17 at 15:27
  • snibbets, do you really want to do that though? The quiver arrows will then partly cover the ticklabels, as they would with ymin=0,clip=false. – Torbjørn T. Apr 23 '17 at 15:41
  • Thanks for your comments. I will add my solution below, although I'm not sure why it works. @PeterGrill I have edited the post and now list the entire file. – snibbets Apr 24 '17 at 1:07
1

I solved the problem by changing

axis x line=middle,

to

axis lines=middle,

which is equivalent to

axis x line=middle,
axis y line=middle,

Now I can see the tick labels on the x axis. Dunno why this works.

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.