pgfplots 没有绘制所有域

pgfplots 没有绘制所有域

我试图在区间 $[-2,5]$ 上绘制函数 $-0.5x^{\frac{4}{3}}-x^{\frac{1}{3}}+1.2x+1$,但负 $x$ 值的图形未绘制。当 $x$ 为负数时,如何获取图形?

\begin{tikzpicture}
 
\begin{axis}[
    axis lines = center,
    xlabel = $x$,
    ylabel = $y$,
    xmin = -2.5, xmax = 4.5,
    ymin = -1.5, ymax = 2.5,
    xtick = {-2,-1.191,-0.103,0,0.292,1,2,4.144}]
    \addplot[
        domain = -5:5,
        samples = 200,
        smooth,
        thick,
        blue,
    ] {-0.5*x^(4/3)-x^(1/3)+1.2*x+1};
\end{axis}
 
\end{tikzpicture}

答案1

这个问题之前已经提过好几次了(1234)。问题似乎在于 PGF 使用对数函数处理根和分数幂的方式。(有关更多详细信息,请参阅这个问题

正如作者所建议的这个答案,你可以使用表达式x/abs(x)*abs(x)^(1/3)来替换,x^(1/3)以避免上述问题。然后你会得到:

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} 

\begin{document}
\begin{tikzpicture}
 
\begin{axis}[
    axis lines = center,
    xlabel = $x$,
    ylabel = $y$,
    xmin = -2.5, xmax = 4.5,
    ymin = -1.5, ymax = 2.5,
    xtick = {-2,-1.191,-0.103,0,0.292,1,2,4.144},
    x post scale=2]
    \addplot[
        domain = -5:5,
        samples = 200,
        smooth,
        thick,
        blue,
    ] {-0.5*x/abs(x)*abs(x)^(4/3)-x/abs(x)*abs(x)^(1/3)+1.2*x+1};
\end{axis}
 
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

\documentclass[border=1 cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
 \begin{axis}[
    axis lines = center,
    xlabel = $x$,
    ylabel = $y$,
    xmin = -2, xmax = 6,
    ymin = -1.5, ymax = 2.5,
    x tick label style={/pgf/number format/precision=3},
    xtick = {-2,-1.191,-0.103,0,0.292,1,2,4.144},
    x post scale=4,
]
    \addplot[
        domain = -2:6,
        samples = 200,
        smooth,
        thick,
        blue,
    ] {-0.5*x^(4/3)-x^(1/3)+1.2*x+1};
\end{axis}
\end{tikzpicture}
\end{document}

非常宽的图表

相关内容