[Date Index]
[Thread Index]
[Author Index]
Re: Just primitive ColorFunction
*To*: mathgroup at smc.vnet.net
*Subject*: [mg87521] Re: Just primitive ColorFunction
*From*: ucervan at gmail.com
*Date*: Sat, 12 Apr 2008 06:57:58 -0400 (EDT)
*References*: <ftfej7$bu7$1@smc.vnet.net> <ftfk8g$fab$1@smc.vnet.net>
> 1. Is there a more appropriate way to force Plot to calculate the
> function value at certain points?
How about (not very clean, but does the work if you really need to use
ColorFunction for this to make it work with Filling):
ep = 0.0001;
Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick,
ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0],
RGBColor[0, 0, 1]] &), ColorFunctionScaling -> False,
Mesh -> {{Pi, Pi + ep, 2 Pi, 2 Pi + ep, 3 Pi, 3 Pi + ep}},
MeshStyle -> None]
and if you still need to add mesh points in the x direction, use:
ep = 0.0001;
Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick,
ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0],
RGBColor[0, 0, 1]] &), ColorFunctionScaling -> False,
Mesh -> {{Pi, Pi + ep, 2 Pi, 2 Pi + ep, 3 Pi, 3 Pi + ep}, 10},
MeshStyle -> {None, Black}, MeshFunctions -> {#1 &, #1 &}]
>
> 2. Is there a way to avoid having to find the zeros of the function
> manually? (More generally: avoid having to calculate the points where
> the colouring changes abruptly.)
Look at these two cases:
1)
Plot[x, {x, 0, 4 Pi}, PlotStyle -> Thick,
ColorFunction -> (If[Mod[IntegerPart[30 #], 2] == 0,
RGBColor[1, 0, 0], RGBColor[0, 0, 1]] &)]
2)
Plot[x, {x, 0, 4 Pi}, PlotStyle -> Thick, Mesh -> 20,
MeshShading -> {Red, Blue}]
Subdividing 1) by color will succeed only if the initial sampling gets
the colored regions right. Then a color based "find root" will need to
be computed for every single "color jump". We will also need to define
what a "jump" or color based Exclusion is.
2) is the way of dealing with subdividing curves and surfaces via the
Mesh/MeshFunctions/MeshShading options.
An Automatic intersection method can be attained in many cases (only
if the mesh functions evaluate to +/- values, so no min/max tangential
intersections) with something like:
Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick, Mesh -> {{0.}},
MeshShading -> {Red, Blue}, MeshFunctions -> {(Sin[#]) &}]
Plot[{x, Sin[x] + x}, {x, 0, 4 Pi}, PlotStyle -> Thick,
Mesh -> {{0.}}, MeshShading -> {Red, Blue},
MeshFunctions -> {(Sin[#]) &}]
Plot[{Cos[x] + x, Sin[x] + x}, {x, 0, 4 Pi}, PlotStyle -> Thick,
Mesh -> {{0.}}, MeshShading -> {Red, Blue},
MeshFunctions -> {(Sin[#] - Cos[#]) &}]
Finally, using all ColorFunction/Mesh/MeshFunctions/Filling options
together:
Plot[{x, Sin[x] + x}, {x, 0, 4 Pi}, PlotStyle -> Thick,
Mesh -> {{0.}}, MeshFunctions -> {(Sin[#]) &},
ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0],
RGBColor[0, 0, 1]] &), ColorFunctionScaling -> False,
Filling -> {1 -> {2}}]
-Ulises Cervantes
WRI
Prev by Date:
**Re: Problem for using "Epilog" to plot legend**
Next by Date:
**Re: Documentation - what is the big secret?**
Previous by thread:
**Re: Just primitive ColorFunction**
Next by thread:
**basic questions**
| |