3
\documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgf}
\begin{document}
    \begin{figure}[h!]
        \centering
        \begin{tikzpicture}[scale=1]
        \begin{axis}[xlabel=x ,ylabel=y,xtick={0,1,...,10} ,grid=major,ytick={-20,-10,...,60}]
        \addplot[no marks, smooth] coordinates{
            (0.5, -7.75)
            (1. , -9.)
            (1.5, -9.75)
            (2.   ,  -10.)
            (2.5  ,   -9.75)
            (3.   ,  -9.)
            (3.5  ,   -7.75)
            (4.   ,  -6.)
            (4.5  ,   -3.75)
            (5.   ,  -1.)
            (5.5  ,   2.25)
            (6.   ,   6.)
            (6.5  ,   10.25)
            (7.   ,   15.)
            (7.5  ,   20.25)
            (8.   ,  26.)
            (8.5  ,   32.25)
            (9.   ,  39.)
            (9.5  ,  46.25)
            (10.  ,    54.) 
            \sqrt{} };

        \addplot[only marks, red!50!black] coordinates{
            (0.5, -7.75)
            (1. , -9.)
            (1.5, -9.75)
            (2.   ,  -10.)
            (2.5  ,   -9.75)
            (3.   ,  -9.)
            (3.5  ,   -7.75)
            (4.   ,  -6.)
            (4.5  ,   -3.75)
            (5.   ,  -1.)
            (5.5  ,   2.25)
            (6.   ,   6.)
            (6.5  ,   10.25)
            (7.   ,   15.)
            (7.5  ,   20.25)
            (8.   ,  26.)
            (8.5  ,   32.25)
            (9.   ,  39.)
            (9.5  ,  46.25)
            (10.  ,    54.) 
        };
        \end{axis}

        \end{tikzpicture}
    \end{figure}
\end{document}
  • 1
    Welcome to TeX.SE! You not load pgfplots package (but twice pgf)! Such MWE newer work! – Zarko Oct 9 at 7:08
1

Your MWE has two issues:

  • for drawing pgfplots you need to load the package pgfplots in preamble (missed, so this MWE haven't ever work)
  • in coordinates you add coordinate \sqrt{} which is unknown to pgfplots, so with it also your MWE newer work

Repairing both and consider only needed packages for your picture, the MWE whic works at any pgfplots version after 1.11 is:

\documentclass[10pt,a4paper]{book}
\usepackage{pgfplots}      % <---
\pgfplotsset{compat=1.16}  % <---

\begin{document}
    \begin{figure}[ht]
        \centering
    \begin{tikzpicture} 
\begin{axis}[
    grid=major,
    xlabel=x,
    xtick={0,1,...,10} ,
    ylabel=y,
    ytick={-20,-10,...,60}
            ]
\addplot[no marks, smooth] coordinates{
    (0.5,-7.75) (1,-9.)     (1.5,-9.75) (2,-10)     (2.5,-9.75)
    (3,-9)      (3.5,-7.75) (4  ,-6.)   (4.5,-3.75) (5  ,-1.)
    (5.5,2.25)  (6, 6)      (6.5,10.25) (7, 15)     (7.5,20.25)
    (8,26)      (8.5,32.25) (9,39)      (9.5,46.25) (10,54)
                                    }; % removed \sqrt{}
\addplot[only marks, red!50!black] coordinates{
    (0.5,-7.75) (1,-9.)     (1.5,-9.75) (2,-10.)    (2.5,-9.75)
    (3,-9)      (3.5,-7.75) (4,-6)      (4.5,-3.75) (5,-1)
    (5.5,2.25)  (6,6)       (6.5,10.25) (7,15)      (7.5,20.25) 
    (8,26)      (8.5,32.25) (9,39)      (9.5,46.25) (10,54)
                                    };
\end{axis}
    \end{tikzpicture}
    \end{figure}
\end{document}

result:

enter image description here

It is not clear why you draw curve and marks separately. The same result you will obtain with:

\documentclass[10pt,a4paper]{book}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
    \begin{figure}[ht]
        \centering
    \begin{tikzpicture} 
\begin{axis}[
    grid=major,
    xlabel=x,
    xtick={0,1,...,10} ,
    ylabel=y,
    ytick={-20,-10,...,60}
            ]
\addplot[mark=*, mark options={fill=red!50!black}, smooth] % <---
    coordinates{
    (0.5,-7.75) (1,-9.)     (1.5,-9.75) (2,-10)     (2.5,-9.75)
    (3,-9)      (3.5,-7.75) (4  ,-6.)   (4.5,-3.75) (5  ,-1.)
    (5.5,2.25)  (6, 6)      (6.5,10.25) (7, 15)     (7.5,20.25)
    (8,26)      (8.5,32.25) (9,39)      (9.5,46.25) (10,54)
                                    };
\end{axis}
    \end{tikzpicture}
    \end{figure}
\end{document}
  • Thank you very much – Baver Oct 9 at 8:34
  • @Baver, you are welcome. Here is habit that instead of saying "thank you" up-vote answer (for what you not yet have enough reputation) or accept answer (with clicking on check mark at top right side of answer). – Zarko Oct 9 at 8:47

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.