在 Tikz 中绘制坐标范围/子集

在 Tikz 中绘制坐标范围/子集

解决了: 如何在 Tikz 中绘制函数的子集:

使用 foreach 命令平滑坐标图的语法

\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}

我只想绘制前 23 个坐标\pts

这不正确,但正在寻找类似的东西:

\path[draw,black] plot [smooth] coordinates {\pts(sum-0),...,\pts(sum-23)};

解决方案:

\def\ptsa{}
\foreach \a in {0,...,23} {\xdef\ptsa{\ptsa(sum-\a)}; }
\path[draw,green] plot [smooth] coordinates {\ptsa};

生成:在此处输入图片描述

相关内容