# Radial shading in an elliptical shape, rather than a circular shape

So as not to make this an XY problem, let me start with what I'm trying to accomplish here. I've been teaching a calculus course, and introducing my students to limits. I've been avoiding epsilons and deltas, but I've been showing them visually what a limit looks like, essentially teaching them the epsilon-delta definition through pictures. For example, this kind of thing:

I always use yellow!40 for the bounds in the codomain, and red!40 for the bounds in the domain.

I want to create two summary tables involving the various types of limits (finite, infinite, one-sided, two-sided, etc), and have little Tikz pictures that remind them visually what these things look like. One table is for the codomain (i.e. whether the limit is finite, infinity, or negative infinity), and the next will be the domain (finite two-sided, finite from the left, the right, infinity, and -infinity). I'm currently doing the first table.

For a finite limit, I have the following Tikz picture:

\documentclass{minimal}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=0.5]

\fill[fill=yellow!40, path fading = east] (0, 0) rectangle (4, 2);
\fill[fill=yellow!40, path fading = west] (0, 0) rectangle (-4, 2);

\begin{scope}
\clip (0, 0) rectangle (4, 2);
\draw[line width=0mm, dashed, path fading = east] (-4, 2) -- (4, 2);
\draw[line width=0mm, dashed, path fading = east] (-4, 0) -- (4, 0);
\draw[line width=0mm, dashed, path fading = east] (-4, 1) -- (4, 1);
\end{scope}

\begin{scope}
\clip (0, 0) rectangle (-4, 2);
\draw[line width=0mm, dashed, path fading = west] (-4, 2) -- (4, 2);
\draw[line width=0mm, dashed, path fading = west] (-4, 0) -- (4, 0);
\draw[line width=0mm, dashed, path fading = west] (-4, 1) -- (4, 1);
\end{scope}

\end{tikzpicture}

\end{document}


Note the fading, to denote that the region continues unboundedly. I would now like something for the infinite limits, where the yellow region continues indefinitely not just east and west, but also either north or south as well. I would also like the fading to reflect this. Plus, it would be good if the size of the picture can be standardised with the previous one (i.e. take place in a box of dimensions 8 x 2).

I was considering doing a radial fading, starting at (0, 0), and clipping to the 8 x 2 box, but this will be a circular fade that will end up clipping rather than properly fading out. Is there a way to make this using some kind of elliptical fade? Note: I would still like a fading dashed line on the (relatively) unfaded edge.

(By the way, I am learning Tikz as I go. I am definitely not strong with it yet.)

• I think opacity can be used instead of fading. Anyway, the figure is nice, pedagogically! Jan 25 at 4:48
• Unrelated: line width=0mm does not make sense. Do not use the minimal class. tex.stackexchange.com/questions/42114/… Jan 25 at 21:19
• @hpekristiansen line width=0pt is perfect. Extract from PDF references "A line width of 0 shall denote the thinnest line that can be rendered at device resolution: 1 device pixel wide." Jan 25 at 22:20

\documentclass[tikz, border=1cm]{standalone}

\draw[left color=transparent!100, right color=transparent!100, middle color=transparent!0] (-4,-2) rectangle (4,2);

\draw[inner color=transparent!0, outer color=transparent!100] (-4,-1.5) rectangle (4,1.5);

\begin{document}
\begin{tikzpicture}
\fill[yellow] (-4,-1) rectangle (4,1);
\draw[dashed] (-4, -1) -- (4, -1) (-4, 0) -- (4, 0) (-4, 1) -- (4, 1);
\end{tikzpicture}
\begin{tikzpicture}
\fill[yellow] (-4,-1) rectangle (4,1);
\draw[dashed] (-4, -1) -- (4, -1) (-4, 0) -- (4, 0) (-4, 1) -- (4, 1);
\end{tikzpicture}
\end{document}


Pedagogically, the simple the better! I avoid to use fading, and dashed lines. I choose Asymptote due to convenient commands size(), unitsize(), and for high customization. The code is automatic with random left and right limits of the vertical strip around the point (a,f(a)). The option opacity(.5) makes the colors red and yellow mixing at the intersection region that is expected.

An animation is nice in this situation. I will add later!

// http://asymptote.ualberta.ca/
unitsize(1cm,8mm);
size(8cm);
import graph;
real f(real x){return x^3;}
real finv(real y){return cbrt(y);}
pair A=(-1,-1),B=(3,3);
real a=1;
pair M=(a,f(a));
path pf=graph(f,A.x,B.x);
real ap=a+.3*unitrand(),am=a-.35*unitrand();
fill(box((am,A.y),(ap,B.y)),red+opacity(.5));
fill(box((A.x,f(am)),(B.x,f(ap))),yellow+opacity(.5));
draw((M.x,0)--M^^(0,M.y)--M,dashed);
draw(pf,blue);
dot(M);
label("$f(x)=x^3$",(finv(B.y),B.y),SE,blue);
label("$a$",(a,0),S);
label("$f(a)$",(0,f(a)),W);
clip(box(A,B));
axes("$x$","$y$");


With srand(10); added