# Using parameter from ParametricPlot as parameter in ColorFunction

Posted 10 years ago
6413 Views
|
2 Replies
|
2 Total Likes
|
 HeyI'm new to this site, so bear with me if I posted in the wrong forum.I'm trying to make a ParametricPlot with parameters r and t, and then color that plot with a ColorFunction, so that the plot becomes more red for increasing r, and more green for increasing t. I can however only make the ColorFunction do this for increasing x[r,t] and y[r,t], meaning that the plot becomes more red the the left and more green towards the top.Minimal (non-)working example. for simplicity my x and y just swaps r and t wrt my ColorFunction.x[t_, r_] = r;y[t_, r_] = t;ParametricPlot[{x[t, r], y[t, r]}, {r, 0, 1}, {t, 0, 1}, ColorFunction -> Function[{t, r}, RGBColor[t, r, 0]], ColorFunctionScaling -> True, AspectRatio -> 1/1]In this case, I get green in top left corner, red in bottom right, and yellow in top right corner. What I expected was for (y=0,x=1 => t=0,r=1) lower right to be green, and similar upper left to be red.If I change variables for the ColorFunction this does not change, suggesting that the ColorFunction is independed of my parameters r and t from ParametricPlot.So how do I get ColorFuction to use my parameters and not my coordinates ?Thanks
2 Replies
Sort By:
Posted 10 years ago
 Go to the main documentation page for  ColorFunction  and look under Details. For ParametricPlot, the arguments passed are  x, y, u  or  x, y, u, v  where x and y are the directions and u and v are the first and second parameters. In  ColorFunction -> Function[{t, r}, RGBColor[t, r, 0]],it does not matter what names you gave the function internal variables; the first two variables passed to the function are the x and y positions.  To include the two parameters, include all four arguments in the header and ignore the first two.ParametricPlot[{x[t, r], y[t, r]}, {r, 0, 1}, {t, 0, 1}, ColorFunction -> Function[{x, y, r, t}, RGBColor[t, r, 0]], ColorFunctionScaling -> True, AspectRatio -> 1/1, FrameLabel -> {"x", "y"}] and make sure the order of variables is correct in the RGBColor call.
Posted 10 years ago
 Thanks. Worked perfectly.