Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: {mg4240] Plot and colors
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Jens-Peer Kuska

Posts: 12
Registered: 12/7/04
Re: {mg4240] Plot and colors
Posted: Jun 28, 1996 9:53 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



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 y-value and the original line information. In the last
step a graphics object is created with the options of Plot ( axes ..).

Hope that helps

Jens








Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.