2

I have three values : azimuth, elevation and an error value at that position. And from that I have a number of such 3 value combinations. So three arrays of azimuths, elevations and correspondng error.

I want to plot a sphere with heat map such that the color of a region would represent the error in that region of the sphere. This would help in figuring out what part of the sphere shows the highest error.

How can I plot this? I tried to create a meshgrid


r = 2
u, v = np.mgrid[0:2.01 * np.pi:(1/10)* np.pi, 0:1.01*np.pi:(1/10)* np.pi]
X = r * np.cos(u) * np.sin(v)
Y = r * np.sin(u) * np.sin(v)
Z = r * np.cos(v)

This would create a mesh. How can one integrate the azimuth, elevation and error at each position into this subregion classification?

1 Answers1

2

You could do it this way:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["figure.figsize"] = [15.00, 6.0]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
r = 2
u, v = np.mgrid[0:2.01 * np.pi:(1/10)* np.pi, 0:1.01*np.pi:(1/10)* np.pi]
X = r * np.cos(u) * np.sin(v)
Y = r * np.sin(u) * np.sin(v)
Z = r * np.cos(v)
ax.plot_surface(X, Y, Z, cmap=plt.cm.YlGnBu_r)
plt.show()

Which returns:

enter image description here

UPDATE

Another way, if you want to introduced points like the ones you want (here, I randomize, but you'll need to format your points in the exact same way if you want to use the code unchanged), you can do this:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm


def random_point(r=2):
    ct = 2*np.random.rand() - 1
    st = np.sqrt( 1 - ct**2 )
    phi = 2* np.pi *  np.random.rand()
    x = r * st * np.cos( phi)
    y = r * st * np.sin( phi)
    z = r * ct
    return np.array( [x, y, z ] )

def near( p, pntList, d0 ):
    cnt=0
    for pj in pntList:
        dist=np.linalg.norm( p - pj )
        if dist < d0:
            cnt += 1 - dist/d0
    return cnt



Azimuth_points = np.array([ random_point(2.02) for i in range(23) ] )

fig = plt.figure()
ax = fig.add_subplot( 1, 1, 1, projection='3d')

u = np.linspace( 0, 2 * np.pi, 120)
v = np.linspace( 0, np.pi, 60 )
r = 2
X = r * np.outer( np.cos( u ), np.sin( v ) )
Y = r * np.outer( np.sin( u ), np.sin( v ) )
Z = r * np.outer( np.ones( np.size( u ) ), np.cos( v ) )

W = X.copy()
for i in range( len(X) ):
    for j in range( len(X[0]) ):
        x = X[ i, j ]
        y = Y[ i, j ]
        z = Z[ i, j ]
        W[ i, j ] = near(np.array( [x, y, z ] ), Azimuth_points, 3)
W = W / np.amax( W )
myheatmap = W

ax.plot_surface( X, Y,  Z, cstride=1, rstride=1, facecolors=cm.jet( myheatmap ) )
plt.show() 

which gives:

enter image description here

  • Hey! Thanks for the reply. I am able to make this graph. What i dont know how to do is to integrate a separate dataframe into this face of the sphere. Based on the azimuth and elevation values I have, how can i plot the corresonding error on top of this sphere surface. I can make the sphere is the representing of the different errors on this surface I am not able to understand how to do. – jakestackexchange Feb 09 '22 at 15:40
  • Have you looked at this https://stackoverflow.com/questions/44594011/heat-map-on-unit-sphere ? – Serge de Gosson de Varennes Feb 09 '22 at 15:43