# How to plot 3D spherical graph using x y data?

I have a problem in which the temperature is given at different radius for spherical ball. The temperature does not vary in theta and phi direction. The 2D representation is shown below:

The radius ranges from [0-112.5]. The data is given as:

r={0, 5.625, 11.25, 16.875, 22.5, 28.125, 33.75, 39.375, 45, 50.625, 56.25, 61.875, 67.5,73.125 78.75, 84.375, 90, 95.625, 101.25, 106.875, 112.5}

T={91.67957977, 91.67957977, 91.67957977, 91.67960856, 91.67960527, 91.6795804, 91.6793762, 91.67778452, 91.66602638, 91.58867628, 91.21715009, 90.23638055, 88.7682609, 87.08880295, 85.33335735, 83.57849684, 81.89021437, 80.34527736, 79.01720822, 77.9780673, 77.29413776}

I am trying to plot the above 2D graph into 3D spherical plot with different colors for temperature without any axis, but showing the scale for temperature similar to the graph shown below:

Thank you.

• Dimensions /@ {r, T} reveals {{20}, {21}} i.e.; a mismatch in sizes of the arrays. Please fix it. Also, can you include Mathematica code for the 2D representation?
– Syed
Commented May 26, 2022 at 7:24
• Thank you for pointing out the error, i have made error while tying the array. Also the figure 1 given here was plotted in origin lab, i wanted a 3d representation of the figure which has been provided by mr. Daniel. Commented May 28, 2022 at 8:24

You could proceed as follows:

-Interpolate the data (delete the last element of T as Syed noted)

-Define a piecewise function that returns 0 for radius > data range

-Use DensityPlot3D with a region function

Here is the code:

fr = Interpolation[Transpose[{r, Most@T}]];
f1[x_, y_, z_] =
Piecewise[{{fr[Sqrt[x^2 + y^2 + z^2]],
Sqrt[x^2 + y^2 + z^2] < 113}, {0, True}}];

m = 113;
DensityPlot3D[f1[x, y, z], {x, -m, m}, {y, -m, m}, {z, -m, m},
Axes -> False, RegionFunction -> Function[{x, y, z}, x < 0 || y > 0],
ColorFunction -> Function[{z}, Hue[7 z]], OpacityFunction -> None]


• Thank you so much for providing the code.This is what I need. Commented May 28, 2022 at 8:26