以下代码可以简化为一行代码吗
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (5.5,0) node [black, xshift=.3cm, yshift=0cm] {$t$};
\draw [thick,-latex](0,-2) -- (0,2.5) node [black, xshift=0cm, yshift=.3cm] {$lt$};
\draw [very thick, blue] (.6,0) +(-45:.5cm) -- +(135:.5cm) node [pos=0,circle, draw, blue, fill=blue, scale=0.4]{} node [pos=1,circle, draw, blue, fill=blue, scale=0.4]{};
\draw [very thick, blue] (1.306,0) +(-135:.5cm) -- +(45:.5cm) node [pos=0,circle, draw, blue, fill=blue, scale=0.4]{} node [pos=1,circle, draw, blue, fill=blue, scale=0.4]{};
\draw [very thick, blue] (2.01,0) +(-45:.5cm) -- +(135:.5cm) node [pos=0,circle, draw, blue, fill=blue, scale=0.4]{} node [pos=1,circle, draw, blue, fill=blue, scale=0.4]{};
\draw [very thick, blue] (2.72,0) +(-135:.5cm) -- +(45:.5cm) node [pos=0,circle, draw, blue, fill=blue, scale=0.4]{} node [pos=1,circle, draw, blue, fill=blue, scale=0.4]{};
\draw [very thick, blue] (3.426,0) +(-45:.5cm) -- +(135:.5cm) node [pos=0,circle, draw, blue, fill=blue, scale=0.4]{} node [pos=1,circle, draw, blue, fill=blue, scale=0.4]{};
\draw [very thick, blue] (4.132,0) +(-135:.5cm) -- +(45:.5cm) node [pos=0,circle, draw, blue, fill=blue, scale=0.4]{} node [pos=1,circle, draw, blue, fill=blue, scale=0.4]{};
\draw [very thick, blue] (4.84,0) +(-45:.5cm) -- +(135:.5cm) node [pos=0,circle, draw, blue, fill=blue, scale=0.4]{} node [pos=1,circle, draw, blue, fill=blue, scale=0.4]{};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
编辑2
@marmot 的评论启发了一个更短的解决方案,不再scope
需要。我刚刚才注意到你没有绘制第一个样本(在x=0
),所以我也删除了它。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}
\draw [thick,-latex](0,0) -- (5.5,0) node [black, xshift=.3cm, yshift=0cm] {$t$};
\draw [thick,-latex](0,-2) -- (0,2.5) node [black, xshift=0cm, yshift=.3cm] {$lt$};
\draw[very thick,blue] plot[mark=*,samples at={1,3,...,15}] ({sqrt(2)/4*\x},{sqrt(2)/4*sin(90*\x)});
\end{tikzpicture}
\end{frame}
\end{document}
编辑
一种不使用的替代方法pgfplots
。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}
\draw [thick,-latex](0,0) -- (5.5,0) node [black, xshift=.3cm, yshift=0cm] {$t$};
\draw [thick,-latex](0,-2) -- (0,2.5) node [black, xshift=0cm, yshift=.3cm] {$lt$};
\begin{scope}[x=0.3536cm,y=0.3536cm]
\draw[very thick,blue] plot[mark=*] coordinates {(0,0) (1,1) (3,-1) (5,1) (7,-1) (9,1) (11,-1) (13,1) (15,-1)};
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
这非常接近:
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}
\begin{axis}[
ymin = -2,
ymax= 2.5,
axis equal,
axis lines=middle,
ticks=none,
xmax = 5.5,
xlabel = \( t \),
ylabel = \( lt \)
]
\addplot+[
very thick,
x filter/.code={\pgfmathparse{#1*0.3536}\pgfmathresult},
y filter/.code={\pgfmathparse{#1*0.3536}\pgfmathresult}]
coordinates {(0,0) (1,1) (3,-1) (5,1) (7,-1) (9,1) (11,-1) (13,1) (15,-1)};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
答案2
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\newcounter{slope}
\newcounter{altslope}
\setcounter{slope}{-45}
\setcounter{altslope}{135}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\begin{tikzpicture}[scale=.9, transform shape]
\draw [thick,-latex](0,0) -- (5.5,0) node [black, xshift=.3cm, yshift=0cm] {$t$};
\draw [thick,-latex](0,-2) -- (0,2.5) node [black, xshift=0cm, yshift=.3cm] {$lt$};
\foreach\x in{1,...,7}{%
\draw [very thick, red] (-.1+.7071*\x,0) +(\theslope:.5cm) -- +(\thealtslope:.5cm) node [pos=0,circle, draw, blue, fill=blue, scale=0.4]{} node [pos=1,circle, draw, blue, fill=blue, scale=0.4]{};
\ifnum\theslope<-90\relax\addtocounter{slope}{90}\else%
\addtocounter{slope}{-90}\fi%
\ifnum\thealtslope<90\relax\addtocounter{altslope}{90}\else%
\addtocounter{altslope}{-90}\fi%
}
\end{tikzpicture}
\end{frame}
\end{document}