I would like to color certain regions of a density plot. I have been
working with ColorFunction unsuccessfully so far. I was wondering if
someone might be able to help me without taking too much of their time.
I would also like to clean up all the errors I am generating, by either
defining my function in a different way OR turning off a few of the
error codes. I realize there are undefined regions in the plot.
Here it is. It was simple enough I didn't even define functions.
cond = {alpha -> Pi/6, lambda -> 2.15, Ei -> Ep - Es}
R = lambda Ei Sqrt[ 1 - (Ep/Ei) Sin[alpha]^2 ]
DensityPlot[R /. cond, {Ep, 0, 6}, {Es,0,4.5}, Mesh->False,
PlotRange->{0,1}, PlotPoints->100 ]
What I would like to do is the following:
R<0 be black
R=0 some bright color.
0<R<1 be shaded where R~0 is dark and R~1 is light.
R>1 be white
R undefined be some other color.
I'm sure this is possible. And I don't need a full solution. But maybe
an example using an IF statement with ColorFunction.
I have come pretty close so far, but the shading from dark to light is
screwed up and doesn't seem linear with R from 0 to 1. What algorithm
does GrayLevel use to normalize it with the function from 0 to 1? Does
anybody know? That might help.
Thanks!
> I would also like to clean up all the errors I am generating, by either
> defining my function in a different way OR turning off a few of the
> error codes. I realize there are undefined regions in the plot.
>
> Here it is. It was simple enough I didn't even define functions.
>
> cond = {alpha -> Pi/6, lambda -> 2.15, Ei -> Ep - Es}
>
> R = lambda Ei Sqrt[ 1 - (Ep/Ei) Sin[alpha]^2 ]
>
> DensityPlot[R /. cond, {Ep, 0, 6}, {Es,0,4.5}, Mesh->False,
> PlotRange->{0,1}, PlotPoints->100 ]
>
> What I would like to do is the following:
>
> R<0 be black
>
> R=0 some bright color.
>
> 0<R<1 be shaded where R~0 is dark and R~1 is light.
>
> R>1 be white
>
> R undefined be some other color.
How about
color[x_]:= Which[x < 0, GrayLevel[1],x == 5, Hue[1],0<x<1, Hue[x],
True, GrayLevel[0]]
Off[Power::infy, DensityPlot::plnr, Infinity::indet,
DensityGraphics::zval]
DensityPlot[Evaluate[R /. cond], {Ep, 0, 6}, {Es,0,4.5},
Mesh->False, PlotPoints->100, ColorFunction->color]
You can avoid some of the problems you're encountering by introducing a
function, f, like
f[Ep_, Es_, alpha_, lambda_] =
lambda Ei Sqrt[1 - Ep/Ei Sin[alpha]^2] /. Ei -> Ep - Es
When Ep==Es there is a problem. Taking a Limit avoids this:
f[Ep_, Ep_, alpha_, lambda_] = Limit[f[Ep, Es, alpha, lambda], Ep ->
Es]
DensityPlot[f[Ep, Es, Pi/6, 2.15], {Ep, 0, 6}, {Es, 0, 4.5},
Mesh -> False, PlotPoints->100, ColorFunction->color];
Cheers,
Paul
____________________________________________________________________
Paul Abbott Phone: +61-8-9380-2734
Department of Physics Fax: +61-8-9380-1014
The University of Western Australia Nedlands WA 6907
mailto:pa...@physics.uwa.edu.au AUSTRALIA
http://www.pd.uwa.edu.au/~paul
God IS a weakly left-handed dice player
____________________________________________________________________