0

I need to indicate the region in which a parabolic function y=f(x) is positive. I want to do this by filling the area above the function f(x). Because the plot, being finite, can only show part of of the area, I want to indicate the remaining area by transitioning from the fill color to white using shading toward the left, right, and top.

Here's a MWE that illustrates the problem I'm having:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \filldraw[lightgray] (-0.8,0.64) parabola bend (0.0,0.0) (0.8,0.64) 
    -- (0.8,0.8) -- (-0.8,0.8); 
  \shade[left color=red] (0.8,0.64) -- (1.0,1.0) -- (0.8,0.8); % works
%  \shade[left color=red] (0.8,0.64) parabola bend (0.0,0.0) (1.0,1.0) 
%    -- (0.8,0.8); % does not work
  \shade[right color=blue,left color=white] (-0.8,0.64) -- (-1.0,1.0) 
    -- (-0.8,0.8); 
  \shade[bottom color=green,top color=white] (-1.0,1.0) -- (-0.8,0.8) 
    -- (0.8,0.8) -- (1.0,1.0); 
\end{tikzpicture}
\end{document}  

I first fill the region above the parabola in gray and then add three pieces (here shown in red, blue, and green to make them easier to see). This gives:

enter image description here

If I were to change the colors red and blue to light gray, this would be close to what I need. The problem is that the bottom boundaries of the red and blue pieces are given by straight lines, not by the parabola. If I uncomment the lines that are commented out in the MWE so that the bottom boundaries are given by the parabola, the color in the red region changes - it becomes much lighter:

enter image description here

My first question is how can I avoid the lighter color? My second question is how to avoid the discontinuity in the function value where the gray and red/blue regions meet?

2
  • Why not just use \fill[bottom color=lightgray,top color=white] (-1,1) parabola bend (0.0,0.0) (1,1)--cycle;
    – Salim Bou
    Jan 3, 2017 at 10:56
  • Because I want the shading to appear only near the boundary of the region that I'm plotting. Jan 3, 2017 at 13:43

1 Answer 1

1

Here a solution with a clipped shade inside parabola

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\begin{scope}   
  \path[clip] (-1,1) parabola bend (0.0,0.0) (1,1)--cycle ;
  \fill[color=lightgray] (-0.8,0.64) parabola bend (0.0,0.0) (0.8,0.64) 
    -- (0.8,0.8) -- (-0.8,0.8)--cycle ;
  \shade[bottom color=green,top color=white](-0.8,0.8)--(0.8,0.8)--(1,1)--(-1,1)--cycle;
  \shade[left color=red,right color=white] (1,1) -- (0.8,0.8)--++(0,-0.5)-|cycle ;
  \shade[right color=blue,left color=white] (-1,1) -- (-0.8,0.8)--++(0,-0.5)-|cycle ;
\end{scope}     
\end{tikzpicture}
\end{document}  

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .