[Tex/LaTex] draw a plot with point

plottikz-pgf

I try to draw something like this:

enter image description here

To do that, I have written some code using TikZ, unfortunately I don't get what I want.

\documentclass{report}
\usepackage{tikz}
  \usetikzlibrary{automata,topaths}
\begin{document}
  \begin{tikzpicture}[x=1cm,y=0.4cm]
    \draw[<->] (-4,0)--(4,0); % l'axe des abscisses
    \draw[<->] (0,-5)--(0,5); % l'axe des ordonnées
    \draw[-] (-3,-2)--(3,4); % l'axe des abscisses

    \draw (-2,1.5) node[anchor=south] {.};
    \draw (-1,1) node[anchor=south] {.};
    \draw (-2,3) node[anchor=south] {.};
    \draw (-1,2.5) node[anchor=south] {.};
    \draw (1,3) node[anchor=south] {.};
  \end{tikzpicture}
\end{document}

The result is:

enter image description here

Best Answer

I would recomend you start using pgfplots to draw graphs. But, if you really want to use a TikZ \node to place the coordinates you can use a \foreach loop to simplify things:

\foreach \Point in {(-2,1.5), (-1,1), (-2,3), (-1,2.5), (1,3)}{
    \node at \Point {\textbullet};
}

enter image description here

Note:

  • The red and blue nodes are to show that the points are being properly placed at the coordinates.

Code:

\documentclass{report}

\usepackage{tikz}
%\usetikzlibrary{automata,topaths}% note neded for this.

 \begin{document}

 \begin{tikzpicture}[x=1cm,y=0.4cm]


 \draw[latex-latex, thin, draw=gray] (-4,0)--(4,0) node [right] {$x$}; % l'axe des abscisses
 \draw[latex-latex, thin, draw=gray] (0,-5)--(0,5) node [above] {$y$}; % l'axe des ordonnées
 \draw[thick] (-3,-2)--(3,4); % l'axe des abscisses

\foreach \Point in {(-2,1.5), (-1,1), (-2,3), (-1,2.5), (1,3)}{
    \node at \Point {\textbullet};
}

\foreach \Point in {(2,-1.5), (1,-1), (2,-3), (1,-2.5), (1,-3)}{
    \node at \Point {$\circ$};
}

% to ensure that the points are being properly centered:
\draw [dotted, gray] (-4,-6) grid (5,5);
\node [red] at (3,2.5) {\textbullet};
\node [blue] at (3,-2.5) {$\circ$};

\end{tikzpicture}
\end{document}