Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

i try to draw something like this :

enter image description here

to do that i have write some code using tikz,unfortunately i dont 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

share|improve this question
2  
You can use \draw (0,0) circle[radius=2pt]; and \fill (0,0) circle[radius=2pt];. –  Paul Gaborit Jun 26 '12 at 21:30
add comment

3 Answers 3

up vote 9 down vote accepted

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}
share|improve this answer
    
IMHO, this is a bad solution: \textbullet and $\circ$ are not perfectly centering on coordinates! –  Paul Gaborit Jun 26 '12 at 22:01
    
@PolGab: Have updated solution to show points are properly placed. –  Peter Grill Jun 26 '12 at 22:15
1  
Are you really sure? Have you used a magnifying glass? Compare your red bullet with \fill (3,2.5) circle(2pt);... –  Paul Gaborit Jun 26 '12 at 22:21
    
@PolGab: Hmmm... Good point. I will look into why this is the case. Thanks for pointing this out. –  Peter Grill Jun 26 '12 at 23:08
    
Look at my answer... –  Paul Gaborit Jun 27 at 15:11
add comment

Just to show how this could be done with pgfplots:

\documentclass{article}
\usepackage{pgfplots}


\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=middle,
    xmin=-10, xmax=10,
    ymin=-10, ymax=10,
    xtick=\empty, ytick=\empty
]
\addplot [only marks] table {
-10 -4
-8  2
-5  5   
-4  7
-3  3
0   6
};
\addplot [only marks, mark=o] table {
-4  -5
-2  -1
-1  -4
2   -3
4   3
6   -1
};
\addplot [domain=-10:10, samples=2, dashed] {1*x+3};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
add comment

A simple solution using my first comment:

\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1cm,y=0.4cm]
  \draw[-stealth] (-3,0)--(4,0) node[right]{x}; % l'axe des abscisses
  \draw[-stealth] (0,-3)--(0,5) node[above]{y}; % l'axe des ordonnées
  \draw[dashed] (-3,-2)--(3,4) node[above]{H}; % une droite...

  \draw (-2,1.5) circle[radius=2pt];
  \fill (-1,1)  circle[radius=2pt];
  \draw (-2,3)  circle[radius=2pt];
  \fill (-1,2.5)  circle[radius=2pt];
  \draw (1,3)  circle[radius=2pt];
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
You could combine all the filled/unfilled circles into a single \fill/\draw command (\fill [radius=2pt] (-1,1) circle [] (-1,2.5) circle;), which saves some typing and makes it easier to adjust the colour and radius for all circles simultaneously. –  Jake Jun 27 '12 at 5:37
    
@Jake: You are right: there are plenty of ways to reduce the size of this code. But it is perhaps too much at once for a beginner. –  Paul Gaborit Jun 27 '12 at 6:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.