I have some n points on a hemisphere (theta in range (0, 90) and phi in range (0, 180)). I want to have a 2D plot of the heatmap since 3D plots have occlusion. In addition, since the n points are located at spaced interval, a smooth plot (say, a Gaussian smoothing) will probably look better.
My attempt: I found polar plot
of matplotlib here which looks something like what I want although (a) the grid coordinates are mislabeled and (b) it is not smoothened for spaced points.
Edit: My minimum working example
import numpy as np
import matplotlib.pyplot as plt
def to_degrees(x):
return x*np.pi/180.0
def get_projection(phi, lmda, phi_0=0.0, lmda_0=to_degrees(90.0)):
# Credits : https://en.wikipedia.org/wiki/Orthographic_map_projection
x = np.cos(phi)*np.sin(lmda - lmda_0)
y = np.cos(phi_0)*np.sin(phi) - np.sin(phi_0)*np.cos(phi)*np.cos(lmda-lmda_0)
return [x, y]
# Adding latitudes and longitudes to give the appearance of a sphere
latitudes = [60, 30, 0, -30, -60] #elevations
longitudes = [0, 30, 60, 90, 120, 150, 180] #azimuths
plt.gca().set_aspect('equal', adjustable='box')
for longitude in longitudes:
prev_point = get_projection(to_degrees(-90.), to_degrees(0))
for latitude in range(-90, 90):
curr_point = get_projection(to_degrees(latitude), to_degrees(longitude))
plt.plot([prev_point[0], curr_point[0]], [prev_point[1], curr_point[1]], 'k', alpha=0.3)
prev_point = curr_point
for latitude in latitudes:
prev_point = get_projection(to_degrees(latitude), to_degrees(0))
for longitude in range(0, 180):
curr_point = get_projection(to_degrees(latitude), to_degrees(longitude))
plt.plot([prev_point[0], curr_point[0]], [prev_point[1], curr_point[1]], 'k', alpha=0.3)
prev_point = curr_point
views = [[-60, 0], [60, 0]] # and similar points of the format [azimuth, elevation]
frequency = [0.5, 0.3] # and similar numbers in range [0,1] for heatmap
for view_idx in range(len(views)):
loc = get_projection(to_degrees(views[view_idx][0]), to_degrees(views[view_idx][1]))
plt.scatter(loc[0], loc[1], s=300, c=np.array(plt.cm.jet(frequency[view_idx])).reshape(1, -1))
plt.show()
to get this
Since I have 11-12 such points spread all over the hemisphere, I want to make the heatmap smooth as well.
from Smooth 2D Plot of Hemispherical Coordinates using matplotlib
No comments:
Post a Comment