My next project I'd like to start working on is Domain Coloring. I am aware of the beautiful discussion at:
How can I generate this "domain coloring" plot?
And I am studying it. However, a lot of the articles on domain coloring refer back to Hans Lundmark's page at:
http://www.mai.liu.se/~halun/complex/domain_coloring-unicode.html
So, I would like to begin my work by using Mathematica to draw these three images based on Hans' notes. I'd appreciate if anyone can provide some code that will produce these images, as I could use it to start my study of the rest of Hans' page.
A very small adjustment. Still learning.
g[{f_, cf_}] :=
DensityPlot[f, {x, -1, 1}, {y, -1, 1}, PlotPoints -> 51,
ColorFunction -> cf, Frame -> False];
g /@ {{Arg[-(x + I y)], "SolarColors"},
{Mod[Log[2, Abs[x + I y]], 1], GrayLevel}}
ImageMultiply @@ %
Not sure where to put my current question, so I'll update here. Just came back to visit and discovered some wonderful answers at the bottom of this list. I do understand the opening code:
f[z_] := (z + 2)^2*(z - 1 - 2 I)*(z + I)
paint[z_] :=
Module[{x = Re[z], y = Im[z]},
color = Blend[{Black, Red, Orange, Yellow},
Rescale[ArcTan[-x, -y], {-Pi, Pi}]];
shade = Mod[Log[2, Abs[x + I y]], 1];
Darker[color, shade/4]]
But then I encounter difficulty with the following code:
ParametricPlot[{x, y}, {x, -3, 3}, {y, -3, 3},
ColorFunctionScaling -> False,
ColorFunction -> Function[{x, y}, paint[f[x + y I]]], Frame -> False,
Axes -> False, MaxRecursion -> 1, PlotPoints -> 50, Mesh -> 400,
PlotRangePadding -> 0, MeshStyle -> None, ImageSize -> 300]
I'm good with the first few lines. Looks like ParametricPlot is plotting points, where x and y both range from -3 to 3 (correct me if I am wrong). I also understand the ColorFunctionScaling and the ColorFunction lines. I understand Axes, PlotRangePadding, MeshStyle, and ImageSize. Where I am having trouble is with what PlotPoints->50 and Mesh->400 are doing.
First of all, my image size is 300. What does PlotPoints->50 mean? Does that mean it will sample and array of 50x50 points out of 300x300 and scale the results to fit in the domain [-3,3]x[-3,3]? My next question is, then those points get colored? And if so, how are the remainder of the points in the image colored? For example, I tried:
Table[ParametricPlot[{x, y}, {x, -3, 3}, {y, -3, 3},
ColorFunctionScaling -> False,
ColorFunction -> Function[{x, y}, paint[f[x + y I]]],
PlotPoints -> n, MeshStyle -> None], {n, 10, 50, 10}]
And the images got a little sharper as the PointPlots->n increased.
Here's another question. What does Mesh->400 do in this situation. For example, I tried lowering the mesh number:
ParametricPlot[{x, y}, {x, -3, 3}, {y, -3, 3},
ColorFunctionScaling -> False,
ColorFunction -> Function[{x, y}, paint[f[x + y I]]], Frame -> False,
Axes -> False, MaxRecursion -> 1, PlotPoints -> 50, Mesh -> 100,
PlotRangePadding -> 0, MeshStyle -> None, ImageSize -> 300]
And was completely surprised that it had an effect on the image, particularly when MeshStyle->None. Here's the image I get:
Why does setting Mesh->100 decrease the sharpness of the image?
One final question I have regards adding the mesh lines. Simon suggested
For the mesh you could do something like Mesh->{Range[-5,5],Range[-5,5]}, MeshStyle->Opacity[0.5], MeshFunctions->{(Re@f[#1+I #2]&),(Im@f[#1+I #2]&)} and cormullion added them to produce a beautiful result, but I tried this:
ParametricPlot[{x, y}, {x, -3, 3}, {y, -3, 3},
ColorFunctionScaling -> False,
ColorFunction -> Function[{x, y}, paint[f[x + y I]]], Frame -> False,
Axes -> False, MaxRecursion -> 1, PlotPoints -> 50,
Mesh -> {Range[-5, 5], Range[-5, 5]}, PlotRangePadding -> 0,
MeshStyle -> Opacity[0.5],
MeshFunctions -> {(Re@f[#1 + I #2] &), (Im@f[#1 + I #2] &)},
ImageSize -> 300]
And got this resulting image.
So I am clearly missing something. Maybe someone could post the code that gives cormullion's last image?
OK, just purchased and installed Presentations package. Tried this:
With[{f = Function[z, (z + 2)^2 (z - 1 - 2 I) (z + I)],
zmin = -2 - 2 I, zmax = 2 + 2 I,
colorFunction = Function[arg, HotColor[Rescale[arg, {-Pi, Pi}]]],
imgSize = 400},
Draw2D[{ComplexDensityDraw[Arg[f[z]], {z, zmin, zmax},
ColorFunction -> colorFunction, ColorFunctionScaling -> False,
Mesh -> 50, MeshFunctions -> {Function[{x, y}, Abs[f[x + I y]]]},
PlotPoints -> {50, 50}]}, Frame -> True, FrameLabel -> {Re, Im},
PlotLabel -> Row[{"Arg coloring and Abs mesh of ", f[z]}],
RotateLabel -> False, BaseStyle -> 12, ImageSize -> imgSize]]
But got this colorless image.
Any thoughts on how to fix this?
PlotPoints
andMesh
. As for the code that generates cormullion's last plot, it would be better to ping them directly with a comment under their answer. $\endgroup$HotColor
as it was done in the first Answer, by @belisarius. $\endgroup$