# How does one plot a three-dimensional electric field in spherical coordinates?

I have the following three-dimensional electric field:

e[r_, θ_, ϕ_, t_] := (Sin[θ]/r)*(Cos[r - t] - Sin[r - t]/r)*{0, 0, 1}


where the {0,0,1} vector is the unit Phi vector. How can I plot the electric field lines in three-dimensional space, with spherical coordinates?

• As far I know, MMA cannot plot any 3D function in other coordinate system than Cartesian. This means that your vector function in other Coordinate System should be transformed to that in a Cartesian one... – José Antonio Díaz Navas Feb 11 '18 at 18:39

Generate the TransformedField and then plot it.

tf = TransformedField["Spherical"->"Cartesian",e[r,θ,φ,1],{r,θ,φ}->{x,y,z}]
VectorPlot3D[tf,{x,-2,2},{y,-2,2},{z,-2,2}]


This plots the vector field at t==1.

• But I want to plot the field in spherical coordinates: why do you convert to Cartesian coordinates? – Michael B. Heaney Feb 11 '18 at 16:32
• When I run e[r_, [Theta]_, [CurlyPhi]_, t_] := (Sin[[Theta]]/r) [Cos[r - t] - Sin[r - t]/r] {0, 0, 1}; VectorPlot3D[ TransformedField["Spherical" -> "Cartesian", e[r, [Theta], [CurlyPhi], 1], {r, [Theta], [CurlyPhi]} -> {x, y, z}], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}] it returns TransformedField::nocoord: {-1.99943,-1.99943,-1.99943} is not a non-empty list of valid variables. – Michael B. Heaney Feb 11 '18 at 16:36
• @MichaelB.Heaney Because VectorPlot3D doesn't have a coordinate system option, as far as I can see. I am assuming that you wish to plot the field as it would appear in a 3D space, for which this works perfectly fine (though you may need to include additional boundaries or tweaking to get precisely the shape you want). Also see edit. – eyorble Feb 11 '18 at 16:37
• OK. Why is it returning "TransformedField::nocoord: {-1.99943,-1.99943,-1.99943} is not a non-empty list of valid variables."? – Michael B. Heaney Feb 11 '18 at 16:41
• It seems likely that you have r, theta, and phi defined, so Clear them or they will be substituted in before TransformedField can transform them. Alternatively, change their instances in the VectorPlot3D command to some consistent dummy variable names. – eyorble Feb 11 '18 at 16:44