1
$\begingroup$

I'm studying the following short code in an answer:

dphi = Pi/30; (* angle *)
rend = 0.99; (* radius *)
pts = Table[
  r*Exp[I N[phi, 30]], {phi, -Pi + dphi/2, Pi - dphi/2, dphi},
 {r, 0, rend, rend/10}]; (* a table of points in the polar coordinate grid*)

toColor[z_] := List @@ ColorConvert[Hue[Arg[N[z]]/(2 Pi)], "RGB"] 
(* generate colors *)

line[pts_] := line[pts, Identity]; (* define a function using the next one*)

line[pts_, func_] := Line[ReIm[func[pts]], VertexColors -> (toColor /@ pts)]
Graphics[{line /@ pts, line /@ Transpose[pts]}]

I can trace line by line to see how the functions Line[] and Graphics[] work. It looks not very natural and very smart to me.

Can this be translated to a version using ParametricPlot instead?

$\endgroup$
5
  • 1
    $\begingroup$ ParametricPlot[] does not have the ability to color mesh lines with a function instead of a solid color. If you're willing to sacrifice that, then yes, this is doable with ParametricPlot[]. $\endgroup$ Sep 19, 2017 at 0:22
  • 1
    $\begingroup$ If you really want to use ParametricPlot[], you need to do some work: Show[Table[ParametricPlot[ReIm[r Exp[I t]], {r, 0, rend}, ColorFunction -> Function[{x, y}, Hue[Arg[x + I y]/(2 Pi)]], ColorFunctionScaling -> False], {t, -Pi + dphi/2, Pi - dphi/2, dphi}], Table[ParametricPlot[ReIm[r Exp[I t]], {t, -Pi + dphi/2, Pi - dphi/2}, ColorFunction -> Function[{x, y}, Hue[Arg[x + I y]/(2 Pi)]], ColorFunctionScaling -> False], {r, 0, rend, rend/10}], Axes -> None, PlotRange -> All] $\endgroup$ Sep 19, 2017 at 0:30
  • $\begingroup$ @J.M. many thanks. $\endgroup$
    – user664
    Sep 19, 2017 at 0:40
  • $\begingroup$ @J.M.: So does your second comment contradict the first one? (Your code works well.) $\endgroup$
    – user664
    Sep 19, 2017 at 1:37
  • 1
    $\begingroup$ The code in the second one is a hack; that is, I generate curves individually and use Show[] to bring them all together at the end. So, the two comments are definitely consistent. It's not doable with a single convenient ParametricPlot[], but you can do it with a little work. $\endgroup$ Sep 19, 2017 at 5:22

1 Answer 1

2
$\begingroup$

Thanks to @J.M.'s comment, I learned that ParametricPlot alone would not work. One can however do the following:

dphi = Pi/30; rend = 0.99; pts = 
 Table[r*Exp[I N[phi, 30]], {phi, -Pi + dphi/2, Pi - dphi/2, 
   dphi}, {r, 0, rend, rend/10}];
Show[
 Table[ParametricPlot[ReIm[r Exp[I t]], {r, 0, rend}, 
   ColorFunction -> Function[{x, y}, Hue[Arg[x + I y]/(2 Pi)]], 
   ColorFunctionScaling -> False], {t, -Pi + dphi/2, Pi - dphi/2, 
   dphi}], Table[
  ParametricPlot[ReIm[r Exp[I t]], {t, -Pi + dphi/2, Pi - dphi/2}, 
   ColorFunction -> Function[{x, y}, Hue[Arg[x + I y]/(2 Pi)]], 
   ColorFunctionScaling -> False], {r, 0, rend, rend/10}], 
 Axes -> None, PlotRange -> All]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.