SOLVED: How would you plot subset of a function in Tikz:
In Syntax for smoothing a coordinate plot with the foreach command
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\begin{document}
\begin{tikzpicture}
% red line
\path[draw,red,name path=one] plot [smooth] coordinates {(0,0) (7.5,0) (8,6) (8.5,0) (10,0)};
% function
\path[draw,blue,name path=three]
plot[domain=0:10,samples=100,smooth] (\x,{0.5*rand+2});
red line + function
\foreach \c in {0,...,100} {
\pgfmathsetmacro{\x}{\c/10}
\path[name path=line] (\x,-1) -- (\x,4);
\path[name intersections={of=one and line,name=newone}];
\path[name intersections={of=three and line,name=newthree}];
\path let \p1=(newone-1), \p2=(newthree-1) in
(\x1,\y1+\y2) coordinate (sum-\c);
}
\def\pts{}
\foreach \x in {0,...,100} { \xdef\pts{\pts (sum-\x)}; }
\draw[black] plot[smooth] coordinates {\pts};
\end{tikzpicture}
\end{document}
I would like to plot only the 23 first coordinates of \pts
This is not correct but looking for something like:
\path[draw,black] plot [smooth] coordinates {\pts(sum-0),...,\pts(sum-23)};
Solution:
\def\ptsa{}
\foreach \a in {0,...,23} {\xdef\ptsa{\ptsa(sum-\a)}; }
\path[draw,green] plot [smooth] coordinates {\ptsa};
Produces:
\foreach \x in {0,...,23} { \xdef\pts{\pts (sum-\x)}; }
should do it.\foreach \x in {0,...,100} { \xdef\pts{\pts (sum-\x)}; }
by\foreach \x in {0,...,23} { \xdef\pts{\pts (sum-\x)}; }
, do you not get what you want?\def\ptsa{}
\foreach \a in {0,...,23} {\xdef\ptsa{\pts(sum-\a)}; };
\path[draw,black] plot [smooth] coordinates {\ptsa};
But for some reason the subplot does not follow the full original plot\def\ptsa{} \foreach \a in {0,...,23} {\xdef\ptsa{\ptsa(sum-\a)}; };...
(Don't reuse\pts
!)\def\ptsa{} \foreach \a in {0,...,23} {\xdef\ptsa{\ptsa(sum-\a)}; } \path[draw,black] plot [smooth] coordinates {\ptsa};
instead?