我想用图案填充曲线下方的区域。曲线有箭头作为装饰。用颜色填充该区域效果很好。
梅威瑟:
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis on top = true,
axis lines = center,
ticks = none,
enlargelimits,
xlabel = $x$,
ylabel = $y$
]
\addplot[
pattern = north west lines,
% fill = yellow,
postaction = {decorate},
decoration = {
markings,
mark=at position 0.3 with {\arrow{stealth}},
mark=at position 0.6 with {\arrow{stealth}}
},
domain = 0:8,
samples = 100
]
{16-(x-4)^2}
\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}
如何才能防止箭头被遮住?
答案1
只需使用 apostaction
作为模式即可。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis on top = true,
axis lines = center,
ticks = none,
enlargelimits,
xlabel = $x$,
ylabel = $y$
]
\addplot[
postaction={pattern = north west lines},
postaction = {decorate},
decoration = {
markings,
mark=at position 0.3 with {\arrow{stealth}},
mark=at position 0.6 with {\arrow{stealth}}
},
domain = 0:8,
samples = 100
]
{16-(x-4)^2}
\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}
存在依赖于查看器的工件,patterns.meta
经常使用可以修复它们。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{patterns.meta}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis on top = true,
axis lines = center,
ticks = none,
enlargelimits,
xlabel = $x$,
ylabel = $y$
]
\addplot[
postaction={pattern={Lines[angle=45,distance={4pt/sqrt(2)}]}},
postaction = {decorate},
decoration = {
markings,
mark=at position 0.3 with {\arrow{stealth}},
mark=at position 0.6 with {\arrow{stealth}}
},
domain = 0:8,
samples = 100
]
{16-(x-4)^2}
\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}
答案2
阅读所说的内容这里fill=white
,您需要在添加模式之前划定一个区域。只需在模式前输入代码即可。希望它能按您想要的方式工作!
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis on top = true,
axis lines = center,
ticks = none,
enlargelimits,
xlabel = $x$,
ylabel = $y$
]
\addplot[
fill = white,
pattern = north west lines,
postaction = {decorate},
decoration = {
markings,
mark=at position 0.3 with {\arrow{stealth}},
mark=at position 0.6 with {\arrow{stealth}}
},
domain = 0:8,
samples = 100
]
{16-(x-4)^2}
\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}