Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: {mg4240] Plot and colors
Posted:
Jun 28, 1996 9:53 AM


here is the principle solution.
Needs["Utilities`FilterOptions`"]
Options[ColorPlot]:= {ColorFunction >Hue,Axes>True}
ColorPlot[f_,{x_,x0_,xe_},opt___]:= Module[{gr,cfun}, cfun=ColorFunction /. {opt} /. Options[ColorPlot]; gr=First[ Plot[ f,{x,x0,xe}, DisplayFunction> Identity ] ] //. Line[{a_,b_,c__}] :> Sequence @@ {Line[{a,b}], Line[{b,c}]} /. Line[{a_,b_}] :> {cfun[Last[a+b]],Line[{a,b}]}; Show[ Graphics[ gr, Sequence @@ {FilterOptions[Graphics,opt], FilterOptions[Graphics,Sequence @@ Options[Plot]]} ] ] ] Now
ColorPlot[Sin[x],{x,0,Pi}]
works. You may set the desired color function with the option ColorFunction. A rescaling to the maximum/min range may be usefull, but this is a quick and dirty solution. Here the explanation. Plot generates one line with all points of the curve, to color the different line segments one must split the one long line into a list of lines connecting only two points, the replacement Line[{a_,b_,c__}] :> .. does this. Than one has to add the color information for every line segment by replacing every line segment by a color directive due to the ave yvalue and the original line information. In the last step a graphics object is created with the options of Plot ( axes ..).
Hope that helps
Jens



