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.

How do I connect the lines of the simplest form in the following code. Perhaps with chain or other option, so that the code is short.

\usetikzlibrary{chains,calc}
\newcommand{\xx}{10}
\newcommand{\yy}{9}
\newcounter{x}    %novo contador
\setcounter{x}{1} %valor inicial do contador
\begin{tikzpicture}[>=latex,start chain=dot placed {at=(\tikzchaincount*30:1.5)}]
    %grade
    \draw[very thin,color=lightgray,dashed] (0,0) grid (\xx+1,\yy+1);
    %eixos
    \draw[->] (-1,0) -- (\xx+1,0) node[below] {$n^\circ$};
    \draw[->] (0,-1) -- (0,\yy+1) node[right] {altura $(m)$};
    %cotas
    \foreach \x in {1,...,\xx}
        \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt)
            node[below]     {$\x$};
    \foreach \y in {1,...,\yy}
    \draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt)
        node[left] {$\y 0$};
    \node[below left] at (0,0) {$0$};
    %grafico
    \foreach \y in {1,3,2,4,5,1,3,6,8,9}{
        \fill[blue] (\thex,\y) circle (2pt);
        \coordinate (p\thex) at (\thex,\y);
        \draw (p\thex) -- (p\thex); %CONECT LINES HERE
        \pgfmathsetcounter{x}{\thex+1} %soma 1 no contador
        \setcounter{x}{\thex} %redefine o contador
    }
\end{tikzpicture}

enter image description here

I need this. enter image description here

I solve with

\usetikzlibrary{calc}
\newcommand{\xx}{10}
\newcommand{\yy}{9}
\begin{tikzpicture}[>=latex]
    %grade
    \draw[very thin,color=lightgray,dashed] (0,0) grid (\xx+1,\yy+1);
    %eixos
    \draw[->] (-1,0) -- (\xx+1,0) node[below] {$n^\circ$};
    \draw[->] (0,-1) -- (0,\yy+1) node[right] {altura $(m)$};
    %cotas
    \foreach \x in {1,...,\xx}
        \draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt)
            node[below]     {$\x$};
    \foreach \y in {1,...,\yy}
    \draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt)
        node[left] {$\y 0$};
    \node[below left] at (0,0) {$0$};
    %grafico
    \coordinate (p1) at (1,1);
    \coordinate (p2) at (2,3);
    \coordinate (p3) at (3,2);
    \coordinate (p4) at (4,4);
    \coordinate (p5) at (5,5);
    \coordinate (p6) at (6,1);
    \coordinate (p7) at (7,3);
    \coordinate (p8) at (8,6);
    \coordinate (p9) at (9,8);
    \coordinate (p10) at (10,9);

    \draw plot[mark=*,mark options={blue}] coordinates{
        (p1)(p2)(p3)
        (p4)(p5)(p6)
        (p7)(p8)(p9)
        (p10)
    };
\end{tikzpicture}
share|improve this question
4  
Why do you want to plot your data this way? It would be a lot easier to just use pgfplots, or at least the plot functionality that comes with TikZ. I believe you might get better answers if you explained the motivation behind your approach. –  Jake Oct 27 '11 at 2:17
add comment

1 Answer

up vote 10 down vote accepted

Here's a pgfplots solution.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel=$n^{\circ}$, ylabel=Altura,
              grid=major, axis lines = left, 
              xmin = 0, ymin= 0, xmax=11,ymax=100, 
              major grid style={dashed},
              xtick={0,1,...,10},ytick={0,10,...,90}] 
\addplot[color=blue,mark=*] 
coordinates {
    (1,10) 
    (2,30) 
    (3,20) 
    (4,40) 
    (5,50) 
    (6,10) 
    (7,30) 
    (8,60) 
    (9,80) 
    (10,90)
};
\end{axis} \end{tikzpicture}
\end{document}

output of code

share|improve this answer
    
I try new command. See, but no sucessful. –  Regis da Silva Oct 27 '11 at 2:14
    
Resolved. Thanks. –  Regis da Silva Oct 27 '11 at 3:37
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.