# Density Plotting 2D and 3D

(*This was already the corrected code answered to me by @TOMI (thanks to you). I modified some to fit what I want. But I still have some issues.

1. The theta which ranges from 0 to 2pi, is presented here as arctan y/x, of course, blows up at x=0. (That we can only use x, y and z as coordinates?) How can I resolve this, knowing that if I use the theta as angle, do not have undefined lines. Thanks in advance!

2. Secondly, how can I change the color for the 3D counterpart, say green.*)

[Lambda] = 54310^-7; f = 50; w0 = 6.27510^-1; zr = ([Pi]w0^2)/[Lambda]; theta = [Lambda]/(Piw0);

wz[z_] := w0*Sqrt[1 + (z/zr)^2];

r[x_, y_] := Sqrt[x^2 + y^2];

ifunc[x_, y_, z_] := Module[{rtemp, result}, rtemp = r[x, y]; result = Exp[-2*(rtemp/wz[z])^2]; Return[result];] Color[z_] := RGBColor[0, z, 0] z = 1 DensityPlot[ ifunc[x, y, z](Cos[2ArcTan[y/x]])^2, {x, -0.2, 0.2}, {y, -0.2, 0.2}, ColorFunction -> Color] DensityPlot3D[ ifunc[x, y, z](Cos[2ArcTan[y/x]])^2, {x, -0.2, 0.2}, {y, -0.2, 0.2}, {z, -1, 1}]

• Use ArcTan[x,y] instead of ArcTan[y/x] Apr 12, 2021 at 6:09
• Thanks, but I suppose I need to add more conditions. I recently found that ArcSin and ArcCos work instead of ArcTan. But still asking help for item 2.
– AMA
Apr 12, 2021 at 15:53