![怎样用最简单的方式连接线路?](https://linux22.com/image/241909/%E6%80%8E%E6%A0%B7%E7%94%A8%E6%9C%80%E7%AE%80%E5%8D%95%E7%9A%84%E6%96%B9%E5%BC%8F%E8%BF%9E%E6%8E%A5%E7%BA%BF%E8%B7%AF%EF%BC%9F.png)
如何连接以下代码中最简单的形式的行。也许使用链或其他选项,以便代码简短。
\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}
我需要这个。
我解决了
\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}
答案1
这是一个pgfplots
解决方案。
\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}