7

Here is the preamble and the code for the graph:

\documentclass[12pt]{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{enumerate}
\pgfplotsset{compat=1.18,width=15cm}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[xmin=-6, xmax=15, ymin=-10, ymax=10,
    axis lines=middle, xlabel=$x$, ylabel=$y$,
   % xticklabel=\empty,yticklabel=\empty,
    ytick={-10,...,10},xtick={-10,...,15}]
        \addplot[color=blue, samples=50]{-1/1000*(x+2)^2*(x-5)*(x-10)^2};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

It should display the whole thing, i.e., the right part below the x axis. Am I missing something?

Note: If you are wondering about the

% xticklabel=\empty,yticklabel=\empty

I was making some graphs with no tick mark labels and some with labels, so I just comment out that line when I want to show the tick labels.

2
  • If you are wondering about the % xticklabel=\empty,yticklabel=\empty, I was making some graphs with no tick mark labels and some with labels, so I just comment out that line when I want to show the tick labels.
    – Kelli A.
    Commented Jun 12 at 5:16
  • Welcome! ......
    – cfr
    Commented Jun 12 at 5:32

1 Answer 1

12

The default domain is -5:5 (page 55 of the manual). Since you've not defined a domain, this is what pgfplots uses.

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{amsmath}
\pgfplotsset{compat=1.18,width=15cm}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[xmin=-6,xmax=15,ymin=-10,ymax=10,
    axis lines=middle, xlabel=$x$, ylabel=$y$,
    % xticklabel=\empty,yticklabel=\empty,
    ytick={-10,...,10},xtick={-10,...,15}]
    \addplot[color=blue, samples=50,domain=-6:15]{-1/1000*(x+2)^2*(x-5)*(x-10)^2};
  \end{axis}
\end{tikzpicture}
\end{document}

plot with domain customised

You might have been thinking that

xmin=-6,xmax=15,ymin=-10,ymax=10

was sufficient to determine the interval(s) over which the function would be plotted, but these values determine only the extent of the axes. They do not affect the values the function takes or can take when constructing the plot.

7
  • @Willie Wong Wouldn't it be better to link to CTAN?
    – cfr
    Commented Jun 12 at 5:34
  • 1
    the link goes directly to the domain entry in the pgfplots manual; linking to CTAN would bring up a manual that the OP has to search through. Considering how big the manual is, I think in this case an argument can be made for linking to the HTML version. Commented Jun 12 at 5:36
  • 1
    @WillieWong The HTML version is significantly harder to read, though. At least for me. Anyway, I'm not really comfortable not linking CTAN if I'm going to link at all, so I've included both. It is possible to link to anchors in PDFs on CTAN but either this PDF isn't the kind you can link to or I don't know how to do it.
    – cfr
    Commented Jun 12 at 5:45
  • both is better than one is better than none, I say. Commented Jun 12 at 5:46
  • 1
    @KelliA. CTAN (ctan.org) is an archive of TeX software, including most packages. The documentation is almost always available there - unless the documentation doesn't exist, basically. I've (just) discovered texdoc.org/index.html but know absolutely nothing about it. If you had a local installation of TeX, the best is to bring up the documentation on your system (if you installed the docs) because that is guaranteed to match the version of the package you're using. But I don't think you can do that on Overleaf.
    – cfr
    Commented Jun 14 at 0:21

You must log in to answer this question.

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