Tikzpicture не показывает множественные заливки

Tikzpicture не показывает множественные заливки

У меня есть следующий код в презентации Beamer:

\begin{frame}[c]{ }
\frametitle{Section 5.2: Definite Integral}  


\begin{center}
\begin{tikzpicture}[scale =1]
  \begin{axis}[
    axis lines=center,
    grid=major,
    xmin=-12.5,
    xmax=12.5,
    ymin=-10.5,
    ymax=10.5,
    xtick = {-12,-10,...,12}, 
    ytick = {-10,-8,...,10}, 
    yticklabel style = {font=\tiny,xshift=0.5ex},
    xticklabel style = {font=\tiny,yshift=0.5ex},
    no marks,
    axis line style={thick, <->},  
    ]
\addplot+[-, samples = 200, thin, black, domain = -12:12 , name path=A] {0};          
\addplot+[<-, samples = 200, thick, blue, domain = -11:-4 , name path=B] {0.5*(x + 4) + 4};       
\addplot+[-, samples = 200, thick, blue, domain = -4:-0 , name path=C] {4};   
\addplot+[-, samples = 200, thick, blue, domain = 0:6, name path=D] {-2*x+4};  
\addplot+[->, samples = 200, thick, blue, domain = 6:10.25, name path=E] {4*(x - 6)-8};
\addplot+[red, opacity = 0.3] fill between[of=A and B,soft clip={domain=-8:-4}]; % filling 
\addplot+[red, opacity = 0.3] fill between[of=A and C,soft clip={domain=-4:-0}]; % filling    
\addplot+[red, opacity = 0.3] fill between[of=A and D,soft clip={domain=0:6}]; % filling  
\addplot+[red, opacity = 0.3] fill between[of=A and E,soft clip={domain=6:10}]; % filling                     
\node[blue] at (axis cs:7,7){{\tiny$y = g(t)$}};            
\end{axis}
\end{tikzpicture}
\end{center} 
\end{frame}

что дает следующую картину: введите описание изображения здесь

Я хочу, чтобы вся область под кривой от t = -8 до t = 10 была заполнена, но она заполняет только первую часть. Как это исправить?

решение1

Я бы посоветовал вам использовать один, plotкогда это возможно, я скопировал ваш, используя те же координаты (для неточных путей я наложил их, и они идеально совпадают). Я также дам вам решение с вашим кодом, так что вы можете выбрать.

Ваш код

\documentclass[tikz, margin=10pt]{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture}[scale =1]
    \begin{axis}[
      axis lines=center,
      grid=major,
      xmin=-12.5,
      xmax=12.5,
      ymin=-10.5,
      ymax=10.5,
      xtick = {-12,-10,...,12}, 
      ytick = {-10,-8,...,10}, 
      yticklabel style = {font=\tiny,xshift=0.5ex},
      xticklabel style = {font=\tiny,yshift=0.5ex},
      no marks,
      axis line style={thick, <->},  
      ]
      \path[name path=axis] (axis cs:-10,0) -- (axis cs:12,0);
    \addplot+[-, samples = 200, thin, black, domain = -12:12 , name path=A] {0};          
    \addplot+[<-, samples = 200, thick, blue, domain = -11:-4 , name path=B] {0.5*(x + 4) + 4};       
    \addplot+[-, samples = 200, thick, blue, domain = -4:-0 , name path=C] {4};   
    \addplot+[-, samples = 200, thick, blue, domain = 0:6, name path=D] {-2*x+4};  
    \addplot+[->, samples = 200, thick, blue, domain = 6:10.25, name path=E] {4*(x - 6)-8};
    \addplot+[red, opacity = 0.3] fill between[of=A and B,soft clip={domain=-8:-4}]; % filling 
    \addplot+[red, opacity = 0.3] fill between[of=A and C,soft clip={domain=-4:-0}]; % filling    
    \addplot+[red, opacity = 0.3] fill between[of=A and D,soft clip={domain=0:6}]; % filling  
    \addplot+[red, opacity = 0.3] fill between[of=A and E,soft clip={domain=6:10}]; % filling                     
  \node[blue] at (axis cs:7,7){{\tiny$y = g(t)$}};            
  \end{axis}
  \end{tikzpicture}
\end{document}

Отдельный участок

\documentclass[tikz, margin=10pt]{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
      axis lines=center,
      grid=major,
      xmin=-12.5,
      xmax=12.5,
      ymin=-10.5,
      ymax=10.5,
      xtick = {-12,-10,...,12}, 
      ytick = {-10,-8,...,10}, 
      yticklabel style = {font=\tiny,xshift=0.5ex},
      xticklabel style = {font=\tiny,yshift=0.5ex},
      no marks,
      axis line style={thick, <->},  
      ]
    \addplot+[<->, samples=200, thick, blue, name path=myplot] coordinates {
        (-11,.5) (-4,4) (0,4) (6,-8) (10.25,9)
    };
    \path[name path=axis] (axis cs:-10,0) -- (axis cs:12,0);
    \addplot+[red, opacity = 0.3] fill between[of=myplot and axis,soft clip={domain=-8:10}]; % filling                     
\node[blue] at (axis cs:7,7){{\tiny$y = g(t)$}};            
\end{axis}
\end{tikzpicture}
\end{document}

И результат в обоих случаях:

введите описание изображения здесь

Связанный контент