帮助一个有绝对值的数值

帮助一个有绝对值的数值

我正在尝试绘制$y=|x|^{1/2}$LaTeX但我不知道该怎么做。我尝试使用此代码

    \begin{tikzpicture}
        \begin{axis}[%
            domain = -3:3,
            samples = 2000,
            axis x line = center,
            axis y line = center,
            xlabel = {$x$},
            ylabel = {$y$},
            ticks = none
            ]
            \addplot[blue] {abs(x)^{\frac{1}{2}}} 
[yshift=3pt] node[pos=.95,left] {$y=|x|^{\alpha}$};
        \end{axis}
    \end{tikzpicture}

但它不起作用。

此外,我需要用一种颜色为图表上方的部分着色,用另一种颜色为图表下方的部分着色(计划的一部分)。

答案1

使用该fillbetween包可以这样做。

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\pgfplotsset{width=10cm,compat=1.15}

\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[%
        samples = 500,
        domain = -3:3,
        xmax=3, xmin=-3,
        ymax=1.75, ymin=-0.1,
        axis x line = center,
        axis y line = center,
        axis on top=true,
        axis line style =ultra thick,
        xlabel = {$x$},
        ylabel = {$y$},
        ticks = none
        ]
        \addplot[name path=A,red, line width=1pt,solid] {abs(x)^(0.5)} [yshift=3pt] node[pos=.95,left] {$y=|x|^{\alpha}$};
         \addplot[draw=none, name path=B] coordinates {(-3,0)(3,0)};
         \addplot[draw=none, name path=C] coordinates {(-3,1.73)(3,1.73)};
        \addplot[blue!10] fill between[of=A and C];  
        \addplot[green!10] fill between[of=A and B];  
    \end{axis}
\end{tikzpicture}

\end{document} 

在此处输入图片描述

答案2

一个简单的可能性是pstricks

    \documentclass[svgnames, pstricks, border=10pt]{standalone}
    \usepackage{pst-plot}

    \begin{document}

    \begin{pspicture*}(-2.95,-2.8)(2.95,2.95)
    \psset{plotpoints=1000, showorigin=false, arrowinset=0.12, linejoin=1}
    \everypsbox{\scriptsize}
    \pscustom[fillstyle =solid, fillcolor=LavenderBlush!50]{\psplot[algebraic, linecolor=Tomato, linewidth=1pt]{-3}{3}{sqrt(abs(x))}\psline(3,1.732)(3,3)(-3,3)\closepath}
    \pscustom[fillstyle =solid, fillcolor=WhiteSmoke, linecolor=RoyalBlue]{\psplot[algebraic, linewidth=1pt]{-3}{3}{sqrt(abs(x))}\psline(3,1.732)(3,-3)(-3,-3)\closepath}
    \psaxes[labelFontSize=\scriptstyle, tickstyle=full, ticksize=2pt -2pt, Dx=1, labelFontSize=\scriptstyle, Dy=1, linecolor=LightSteelBlue]{->}(0,0)(-3,-2.8)(2.96,2.95)[$x$,-120][$y$,210]
    \end{pspicture*}

    \end{document} 

在此处输入图片描述

答案3

如果我编译这个:

\documentclass{article}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
  \filldraw[fill=white!50!yellow,domain=-4:4,samples=500,draw=white!50!yellow]
    plot(\x,{sqrt(abs(\x))})--(-4,2)--cycle;
  \filldraw[fill=white!50!green,domain=-4:4,samples=500,draw=white!50!green]
    (-4.1,2)--plot(\x,{sqrt(abs(\x))})--(4.1,2)--(4.1,-.1)--(-4.1,-.1)--cycle;
  \draw[thick,black,domain=-4:4,samples=500] plot(\x,{sqrt(abs(\x))});
  \draw (-4.1,0)--(4.1,0);
  \draw (0,-.1)--(0,2.1);
\end{tikzpicture}
\end{document}

然后我得到这个:

在此处输入图片描述

答案4

再试一次:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \draw[gray!20] (-4,0) grid (4,2);
        \draw[line width=2pt,black,domain=-4:4,samples=600] plot(\x,{sqrt(abs(\x))});
    
        \foreach \i in {-4,-3,...,4}
            \draw[gray!50!cyan] (\i,.1)--(\i,-.1) node[below] (){\footnotesize $\i$};
        \foreach \j in {1,2}
            \draw[gray!50!cyan] (.1,\j)--(-.1,\j) node[left] (){\footnotesize$\j$};
            \draw[gray!50!cyan,-latex](-4.2,0)--(4.2,0) node[right] () {$x$};
        \draw[gray!50!cyan,-latex](0,-.1)--(0,2.3) node[left] () {$y$};
        \node at (0,2.7) () {$y=\sqrt{|x|}$};
    \end{tikzpicture}
\end{document}

他的输出是:

在此处输入图片描述

相关内容