# Contour plotting temperature data on a hemisphere or circle

(edited question:) I solved the Laplace equation(PDE) in spherical coordinates (in my problem temperature is steady and it is azimuthal(θ) symmetric, so my data is only a function of r and φ.) Note that I defined the coordinates as Spherical[r, φ, θ].

Now I want to make a contour plot of this data (temperature would be contoured) on the surface of a solid hemisphere(not a hollow one), but I am having problems.

This is the data that should be contoured on a hemisphere of radius 2 (u[r, φ], in which: 0 < r < 2 & 0 < φ < π)

K[n_] := (2 n + 1)/(n*(2^n))Integrate[10 φ LegendreP[n, Cos[φ]] Sin[φ], {φ, 0, π}] // N
u[r_, φ_] := Sum[K[n] r^n LegendreP[n, Cos[φ]], {n, 1, 8}]


After days probing for ans,I tried simpler contour instead of hemisphere and all of them didn't give any answer and were just running..!(except one 2D contourplot which was evaluated after an hour!) But when @WateSoyan answered my question(as below is shown) he solved the "running time" problem,he just put out the "Hue" from code, by using a pure function( #..&) and this accelerated the evaluation amazingly!!but I added Rescale function into the Hue,'coz making the domain (0...1),despite these efforts, YET the color gradients and mesh lines are NOT ideal(as the examples I show here with 2Dcontour or with Maple)" how can the 3Dplot be corrected?

1=> Last edition of my 3D code

plots = RegionPlot3D[(x <= 0) && 0 <= x^2 + y^2 + z^2 < 4, {x, -3,
3}, {y, -3, 3}, {z, -3, 3},
ColorFunction -> Function[{x, y, z}, #],
PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}}, PlotPoints -> 100,
MaxRecursion -> 10] &@
Hue[Rescale[u[Sqrt[x^2 + y^2 + z^2], ArcCos[z/Sqrt[x^2 + y^2 + z^2]]],
{u[2, 0], u[2, Pi]}]]


result=>

2Dcontour code which this one is somehow a correct answer=

ContourPlot[#1, {x, -2, 2}, {y, -2, 2},
RegionFunction -> Function[{x, y, z}, 0 < x^2 + y^2 < 4]] & @
u[Sqrt[x^2 + y^2], ArcCos[y/Sqrt[x^2 + y^2]]]


For an analogy to the right answer,I put my code and result of it in Maple,which I'd done last week very easy!=>

K := (2*n+1)*(int(10*phi*LegendreP(n, x)*sin(phi), phi = 0 .. Pi))/n(10)^n
u := (rho, phi) ↦ add(K*simplify(LegendreP(n, cos(phi)))*rho^n, n = 0 .. 10)
#plotting=> #
contourplot([rho, phi, u(rho, phi+(1/2)*Pi)], rho = 0 .. c, phi = -Pi .. Pi,
coords = cylindrical, filledregions = true)


contour plotting in Maple in less than 30 seconds=>

• if this is hard to make,if any one(instead of this) can help me for 2 plots,1.one a complete sphere of radius 10 on which u[10,phi] ((0<phi<Pi)) is contoured on surface and 2.a 2D-contourplot of the inner section of the sphere which should be contoured by u[r,phi] ((0<r<10 & 0<phi<Pi)) ,i would appreciate & thank. – pccity May 11 '15 at 20:37
• Please, head to the help centre and format your code properly in the future. Did you like the post in its original version ? I doubt it. Make it easier for us as well as you to read it and when you come back at some point in the future you can pick up right where you were the previous time. Try to highlight the problems you are having, simplify the example as much as possible and show your effort. Those are the basics that will make your question attractive and will probably result in an answer. – Sektor May 11 '15 at 20:45
• hi dear Sektor,definitely you're right,I tried much to ask in direct and well shaped,but your edition made question much better,next time I will try more buddy,tnx ;) – pccity May 11 '15 at 20:53
• – Rahul May 11 '15 at 23:15
• You first define u and then suddenly plot um, where'd this new one come from? – J. M. is away May 15 '15 at 11:27

I think your ColorFunction may be used incorrectly, and my edition is

Clear[k, u]
k[n_] := (2 n + 1)/(n*(2^n)) Integrate[10 \[CurlyPhi] LegendreP[n,
Cos[\[CurlyPhi]]] Sin[\[CurlyPhi]], {\[CurlyPhi], 0, \[Pi]}] // N
u[r_, \[CurlyPhi]_] :=
Evaluate@Sum[k[n] r^n LegendreP[n, Cos[\[CurlyPhi]]], {n, 1, 8}];

plots = RegionPlot3D[(x <= 0) && 0 <= x^2 + y^2 + z^2 < 4, {x, -3, 3},
{y, -3, 3}, {z, -3, 3},
ColorFunction -> Function[{x, y, z}, #],PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}},
PlotPoints->100,MaxRecursion -> 10] &@
Hue[u[Sqrt[x^2 + y^2 + z^2], ArcCos[z/Sqrt[x^2 + y^2 + z^2]]]]


• Thank you @WateSoyan,by putting out Hue function from the body of code you helped alot,but it need a "Rescale" func. in the Hue parameters because they shoould be (0-1),I made some edition on your code and put it again in my Question also with the plot of result, now there are 2problems: 1. "YET the color gradients and mesh lines are NOT ideal(as the question plots)" how can it be corrected? 2.I didn't get why putting out the "Hue" from code, by using a pure function can accelerate the evaluation?!!? can anyone explain a bit – pccity May 15 '15 at 23:08
• @pccity My code works because I let ColorFunction know what should u and k be ! If you replace RegionPlot3D with an arbitary head ,says s.You can see the argument of ColorFunction include u and k! – WateSoyan May 16 '15 at 0:49
• @pccity It ideed needs some patience to answer your messy question. – WateSoyan May 16 '15 at 1:01
• thank for your answer,I changed that with an arbitrary lettar and understood what u mean,but I'm wondering why a pure function(#...&)can make this difference?!? But about claiming that contourplot is correct,I knew that and I exactly had written in my edited question that the issue is correcting the 3Dcode(like the contourplot)At last I think it's not fair at all to call my question messy,I waited 5days and no one ansered me as a newbie here,so I explained it again comprehensively and percisely,finally at the 5th day U did a favor to answer,I tried to be ordered as much as possibl – pccity May 16 '15 at 10:28
• @pccity Don't forget to upvote my answer in turn.I have upvoted you. – WateSoyan May 16 '15 at 12:23