1

I've to plot this function: y=-0.002822*x^2 + 1.456*x - 89.314 in the x domain between 75 and 200, and y domain between 0 to 100. If I use

\begin{tikzpicture}
\begin{axis}[xmin=75,ymin=0]
\addplot[]{-0.002822*(x^2) + 1.456*x - 89.314};
\end{axis}
\end{tikzpicture}

It gives back an empty graph.

  • 2
    Have you tried xmin=75,xmax=200,ymin=0,ymax=100,domain=75:200? (in other words, writing in pgfplots what you said in text...). And please, make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Rmano Jul 6 '16 at 14:18
  • ok it works, ty. – Motosega Jul 6 '16 at 14:19
  • 1
    The default domain is -5:5. – Torbjørn T. Jul 6 '16 at 15:19
2

These are the default values for domain, y range and x range in pgfplots:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.13}
\usetikzlibrary{arrows.meta,positioning,calc}
\begin{document}
\begin{tikzpicture}[
    ]
        \begin{axis}[
            ]
            \addplot {x};
        \end{axis}
\end{tikzpicture}
\end{document}

showing pgfplots defaults

If you want different things, just specify them:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.13}
\usetikzlibrary{arrows.meta,positioning,calc}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[xmin=75, xmax=200,
           ymin=0,ymax=100,
           domain=75:200]
        \addplot[]{-0.002822*(x^2) + 1.456*x - 89.314};
    \end{axis}
\end{tikzpicture}
\end{document}

Correct image

Notice that the default for x and y range is to autoscale them, so really you could just say, setting just your domain:

\begin{tikzpicture}
    \begin{axis}[
           domain=75:200]
        \addplot[]{-0.002822*(x^2) + 1.456*x - 89.314};
    \end{axis}
\end{tikzpicture}

and have

autoscaled

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.