为什么曲线之间的填充区域被切割成 X 形?

为什么曲线之间的填充区域被切割成 X 形?

我想要填充线 $y=1$ 和 $y=3$ 之间的区域。

我该如何修复代码?

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{tkz-tab}
\usepackage{tkz-euclide}
\usepackage{xcolor}

\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{datavisualization}
\newcommand{\AxisRotator}[1][rotate=0]{
\tikz [x=0.25cm,y=0.60cm,line width=.2ex,-stealth,#1] \draw (0,0) arc (-150:150:0.8 and 0.8);}
\linespread{1.5}

\begin{document}
        \begin{tikzpicture}
            \begin{axis}[width=20cm,axis equal image, xticklabel style={font=, below left}, 
               yticklabel style={font=, above right}, axis lines=middle,
                xmin=-2,xmax=2.5,
                ymin=-1,ymax=4,
                xtick={0},ytick= 
                {1,3},
                xticklabels={0},yticklabels= 
                {1,3},
                axis line style={very thick, latex-latex},
                axis line style={->},
                x label style={at={(ticklabel* cs:1)},
                    anchor=west,},
                y label style={at={(ticklabel* cs:1)},
                    anchor=south},
                xlabel={$x$},
                ylabel={$y$}
                ]
                \addplot[name path=A, very thick, samples=300, domain=0:1.6] (x,x^3);
                \addplot[name path=B, very thick, samples=300, domain=-1.6:0] (x,-x^3);
                \addplot[dashed, samples=300, domain=-3:0] (x,x^3);
                \addplot[dashed, samples=300, domain=0:3] (x,-x^3);
                \draw (-1,1) arc (180:360:1 and 0.2);
                \draw[dashed] (-1,1) arc (180:0:1 and 0.2);
                \draw (1.44,3) arc (0:180:1.44 and 0.2);
                \draw (-1.44,3) arc (180:360:1.44 and 0.2);
                \draw[thick] (-1,1)--(1,1);
                \draw[thick] (-1.44,3)--(1.44,3);
                \addplot[teal!50, opacity=0.45] fill between[of=A and B, soft clip={domain 
                 y=1:3}, reverse=true];
                \node [above] at (1.8,3.5) {$ y=x^3 $};
                \node [anchor=north] at (axis cs:.1,-.04) {$ 0$};
      \end{axis}
  \end{tikzpicture}
    
  \end{document}

在此处输入图片描述

答案1

通过反转域进行反向绘制。

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{tkz-tab}
\usepackage{tkz-euclide}
\usepackage{xcolor}

\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{datavisualization}
\newcommand{\AxisRotator}[1][rotate=0]{
\tikz [x=0.25cm,y=0.60cm,line width=.2ex,-stealth,#1] \draw (0,0) arc (-150:150:0.8 and 0.8);}
\linespread{1.5}

\begin{document}
        \begin{tikzpicture}
            \begin{axis}[width=20cm,axis equal image, xticklabel style={font=, below left}, 
               yticklabel style={font=, above right}, axis lines=middle,
                xmin=-2,xmax=2.5,
                ymin=-1,ymax=4,
                xtick={0},ytick= 
                {1,3},
                xticklabels={0},yticklabels= 
                {1,3},
                axis line style={very thick, latex-latex},
                axis line style={->},
                x label style={at={(ticklabel* cs:1)},
                    anchor=west,},
                y label style={at={(ticklabel* cs:1)},
                    anchor=south},
                xlabel={$x$},
                ylabel={$y$}
                ]
                \addplot[name path=A, very thick, samples=300, domain=0:1.6] (x,x^3);
                \addplot[name path=B, very thick, samples=300, domain=0:-1.6] (x,-x^3);
                \addplot[dashed, samples=300, domain=-3:0] (x,x^3);
                \addplot[dashed, samples=300, domain=0:3] (x,-x^3);
                \draw (-1,1) arc (180:360:1 and 0.2);
                \draw[dashed] (-1,1) arc (180:0:1 and 0.2);
                \draw (1.44,3) arc (0:180:1.44 and 0.2);
                \draw (-1.44,3) arc (180:360:1.44 and 0.2);
                \draw[thick] (-1,1)--(1,1);
                \draw[thick] (-1.44,3)--(1.44,3);
                \addplot[teal!50, opacity=0.45] fill between[of=A and B, soft clip={domain 
                 y=1:3}, reverse=true];
                \node [above] at (1.8,3.5) {$ y=x^3 $};
                \node [anchor=north] at (axis cs:.1,-.04) {$ 0$};
      \end{axis}
  \end{tikzpicture}
    
  \end{document}

实心抛物线

相关内容