# ListPlot with spherical coordinates with data from file [closed]

I have a file that is a table of values for r, $\theta$ and f(r,$\theta$) with r and $\theta$ being spherical coordinates, $\phi$ being 0 the whole time. The data thus looks like {{0.1,0.01,2},{0.1,0.02,2.1},{0.1,0.03,2.05},...}

How do I plot this in a nice way? I do not want r- and $\theta$-axes but rather convert it to an xz-grid, I guess. Is there any neat way to do this?

I just had the idea of converting the variables by myself typing this but also have no idea how to do that either.

Any help is appreciated!

So a little more thinking solved the problem: I read the data, create an empty array of the same size and transform coordinates by hand.

datalist = ReadList["file.dat", Number, RecordLists -> True];
data2 = Array[0, {Length[datalist], 3}];

For[i = 1, i < Length[datalist], i++,
For[j = 1, j <= 3, j++,
If[j == 1, data2[[i, j]] = datalist[[i, 1]]*Sin[datalist[[i, 2]]]];
If[j == 2, data2[[i, j]] = datalist[[i, 1]]*Cos[datalist[[i, 2]]]];
If[j == 3, data2[[i, j]] = datalist[[i, j]]]
]
]

ListPlot3D[data2]


Not sure if this is the most elegant way but it worked.

Thanks for the input and next time I will do my best to state the problem more clearly ;)

-

## closed as off-topic by Kuba, RunnyKine, Oleksandr R., Yves Klett, m_goldbergMay 7 '14 at 20:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Kuba, RunnyKine, Oleksandr R., Yves Klett, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

Give us some Mathematica code and you input file :) –  Öskå May 7 '14 at 9:16
Is ListPolarPlot what you're looking for? –  Mike Honeychurch May 7 '14 at 9:36
The file is too big to post it here ;) So far I just managed to read the data from file. Now I'm working on my second approach converting the variables by hand. –  user14170 May 7 '14 at 9:37
@Mike Honeychurch: ListPolarPlot works with a $\theta \in [0,2*\pi]$, while my angle is just the azimutal angle $\theta \in [0,\pi]$. Also I would need something like a 3d or colorplot –  user14170 May 7 '14 at 9:40
It's part of a wavefunction, so a interpolated plain (color or 3d-wise) would be my choice. –  user14170 May 7 '14 at 9:56

One way to do this is to interpolate the data in polar coordinates and just make the coordinate transformation in the plotting function.

fakedata =
Table[{r, θ, r^2 Sin[5 θ]}, {r, 0.01, 1, 0.01}, {θ, 0.01, π, 0.01}] ~Flatten~ 1;

f = Interpolation[{{#1, #2}, #3} & @@@ fakedata];

ContourPlot[f[Sqrt[x^2 + z^2], ArcTan[z, x]], {x, 0, 1}, {z, -1, 1},
RegionFunction -> (#1^2 + #2^2 < 1 &),
Contours -> 20, AspectRatio -> Automatic, ColorFunction -> "Rainbow"]


-

I post this for illustrative purposes. I generate random points in spherical coordinates, coordinate transform and plot. Note: (r,$\theta$,$\phi$) here $\theta$ is colatitude [(0,$\pi$) ] as clarified in comments:

ListPointPlot3D[
CoordinateTransform["Spherical" -> "Cartesian", #] & /@
Transpose[{RandomReal[{1, 3}, 100], RandomReal[{0, Pi}, 100],
ConstantArray[0, 100]}]]
`

-