1

Edit: I wrote some nonsense before. Hopefully it makes more sense now.

I'm trying to repeat a plot in a foreach loop with the domain of the plot shifting in each iteration. I've tried shifting the parameters in the 'domain' argument to 'plot', i.e. domain={\i:2.2*pi+\i}. This fails to compile. It doesn't seem to like the \i variable in the domain. Any ideas on how to make this work?

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}

\foreach \i in {10, 20, 30}
  \draw[] plot[samples=100,domain={\i:2.2*pi + \i}] function {sin(x)};

\end{tikzpicture}
\end{document}

Note that I don't want a plot with axes, and I need the plot to be in the same units as the rest of my tikz drawing. So, I may be wrong, but I don't think 'addplot' is a valid solution.

1 Answer 1

2

Replace foreach with \foreach.

plot function{<gnuplot formula>} is used for gnuplot, see pgfmanual sec 22.6 Plotting a Function Using Gnuplot.

If you want to draw the function plot with pure tikz, follow the examples in pgfmanual sec 22.5 Plotting a Function

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \i in {10, 20, 30}
  \draw plot[samples=100,domain={\i:(2.2*pi + \i)}] (\x, {sin(\x r)});
\end{tikzpicture}
\end{document}
1
  • foreach was just a typo in this post. It's great that I can do it without gnuplot. Thanks. Jul 4, 2020 at 14:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .