对于显示的 MWE:
我需要使用“绘图命令”填充 tikz 中绘制的函数下方的区域。但是,使用“绘制命令”中的“填充”选项不会产生任何结果。
我有时需要填充地块下方的区域,有时需要填充地块上方的区域。
我还可以用垂直线等图案替换填充吗?...
此外,有没有办法只填充/孵化此类地块内的某个区域?
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[help lines,step=0.5](0,0) grid(15,24);
\begin{scope}[shift={(0,6)}]
\draw[thick,color=red,fill=yellow,domain=0:6] plot (\x, {0.1*(5*-1)*(\x*6)/(12)});
\draw[thick,color=red,fill=yellow,domain=6:12] plot (\x, {0.1*(5*-1)*((12-\x)*(6))/(12)});
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}
答案1
代码:
\documentclass[tikz,border=12mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines,step=0.5](0,0) grid(15,10);
\begin{scope}[shift={(0,6)}]
\fill [yellow] (0,-1.5) -- plot[domain=0:6] (\x, {0.1*(5*-1)*(\x*6)/(12)});
\draw[thick,color=red,domain=0:6] plot (\x, {0.1*(5*-1)*(\x*6)/(12)});
\fill [yellow] (6,0)-- plot[domain=6:12] (\x, {0.1*(5*-1)*((12-\x)*(6))/(12)});
\draw[thick,color=red,domain=6:12] plot (\x, {0.1*(5*-1)*((12-\x)*(6))/(12)});
\end{scope}
\end{tikzpicture}
\end{document}
输出:
代码2:
\begin{tikzpicture}
\draw[help lines,step=0.5](0,0) grid(15,10);
\begin{scope}[shift={(0,6)}]
\fill [yellow] plot[domain=0:6] (\x, {0.1*(5*-1)*(\x*6)/(12)})--(6,0);
\draw[thick,color=red,domain=0:6] plot (\x, {0.1*(5*-1)*(\x*6)/(12)});
\fill [yellow] (6,0)-- plot[domain=6:12] (\x, {0.1*(5*-1)*((12-\x)*(6))/(12)});
\draw[thick,color=red,domain=6:12] plot (\x, {0.1*(5*-1)*((12-\x)*(6))/(12)});
\end{scope}
\end{tikzpicture}
输出:
代码3:
\begin{tikzpicture}
\draw[help lines,step=0.5](0,0) grid(15,10);
\begin{scope}[shift={(0,6)}]
\fill [yellow] (0,-1.5) -- plot[domain=0:6] (\x, {0.1*(5*-1)*(\x*6)/(12)});
\draw[thick,color=red,domain=0:6] plot (\x, {0.1*(5*-1)*(\x*6)/(12)});
\fill [yellow] plot[domain=6:12] (\x, {0.1*(5*-1)*((12-\x)*(6))/(12)})--(12,-1.5);
\draw[thick,color=red,domain=6:12] plot (\x, {0.1*(5*-1)*((12-\x)*(6))/(12)});
\end{scope}
\end{tikzpicture}
输出: