我有一些位于半球上的点(theta在0到90的范围内,phi在0到180的范围内)。我希望绘制一个二维热图,因为三维图形会产生遮挡。此外,由于n个点位于间隔均匀的位置,平滑的图形(例如高斯平滑)可能看起来更好。
我的尝试:我在matplotlib的这里找到了一个极坐标图,它看起来有点像我想要的,但是(a)网格坐标标错了,(b)没有对间隔点进行平滑处理。
编辑:我的最小工作示例
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()
获得这个
由于我有11-12个这样的点分布在整个半球上,我希望使热图变得更加平滑。
griddata
和pcolormesh
是否与您想要的视觉效果接近? - Asmus