帮助 tikzpicture

帮助 tikzpicture

有人可以帮我得到这个吗?

在此处输入图片描述

这就是我目前拥有的

在此处输入图片描述

\def\FunctionF(#1){1-(#1)*(#1))} 
\def\FunctionB(#1){abs((#1))} 
\begin{tikzpicture}
\begin{axis}[
        axis y line=center,
        axis x line=middle, 
        axis on top=true,
        xmin=-4,
        xmax=4,
        ymin=-3,
        ymax=4,
        height=7.0cm,
        width=8.0cm,
        xtick={-5,...,1},
        ytick={-2,...,2},
        xlabel=$x$,
        ylabel=$y$,
   ]
\addplot [domain=-2:2, samples=100, mark=none,thick,<->, name path=F]
{\FunctionF(x)};
\addplot [domain=-3:3, samples=100, mark=none,thick,<->, name path=B]
{\FunctionB(x)};
\end{axis}
\end{tikzpicture}

答案1

这里有一个可能性。我定义一个新函数,该函数使用abs(x)1-x^2取决于的值abs(x),并将其用作的“边界”路径之一fill between。另一个边界是沿 x 轴延伸的路径。通过使用split,可以为两部分设置不同的样式。

ode 的输出

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[
  declare function={
    FA(\x)=1-\x^2;
    FB(\x)=abs(\x);
    intersect=(-1 + sqrt(5))/2;
    % intersection of functions at x = +- (sqrt(5)-1)/2
    % if abs(x) > (sqrt(5)-1)/2, use function FA, else use FB
    FAB(\x)=abs(\x)>intersect ? FA(\x) : FB(\x);
  }
]
\begin{axis}[
        axis y line=center,
        axis x line=middle, 
        axis on top=true,
        xmin=-4,
        xmax=4,
        ymin=-3,
        ymax=4,
        height=7.0cm,
        width=8.0cm,
        xtick={-1,1},
        ytick={1},
        xlabel=$x$,
        ylabel=$y$,,
        clip=false
   ]
\addplot [domain=-2:2, samples=100, mark=none,thick,<->] {FA(x)}
  node[above right] {$y=1-x^2$};
\addplot [domain=-3:3, samples=3, mark=none,thick,<->] {FB(x)}
  node[above left] {$y=|x|$};

% draw invisible path along x-axis
\path [name path=xax] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);

% invisible plot along the upper part of domain
\addplot [forget plot,draw=none,domain=-1:1,samples=101,name path=FB] {FAB(x)};

% fill between 
\addplot fill between[
           of=xax and FB,
           % split at every crossing of the paths
           split,
           % different styles for different parts
           every segment no 1/.style={pattern=north east lines},
           every segment no 2/.style={pattern=north west lines}
           ];

\end{axis}
\end{tikzpicture}
\end{document}

相关内容