【发布时间】:2017-11-19 12:17:44
【问题描述】:
我想使用 python 的 matplotlib 库在单位球体上绘制热图。有几个地方讨论了这个问题。就像这样:Heat Map half-sphere plot
我可以部分做到这一点。我可以创建球体和热图。我有坐标矩阵 X、Y 和 Z,它们的大小相同。我有另一个与 X、Y 和 Z 大小相同的变量,其中包含用于创建热图的标量。但是,如果 c 在其第一行和最后一行中包含与零不同的标量,则只有一个极帽会被着色,而另一个不会被着色。生成上述结果的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
#Creating the theta and phi values.
theta = np.linspace(0,np.pi,100,endpoint=True)
phi = np.linspace(0,np.pi*2,100,endpoint=True)
#Creating the coordinate grid for the unit sphere.
X = np.outer(np.sin(theta),np.cos(phi))
Y = np.outer(np.sin(theta),np.sin(phi))
Z = np.outer(np.cos(theta),np.ones(100))
#Creating a 2D matrix contains the values used to color the unit sphere.
c = np.zeros((100,100))
for i in range(100):
c[0,i] = 100
c[99,i] = 100
#Creat the plot.
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
ax.set_axis_off()
ax.plot_surface(X,Y,Z, rstride=1, cstride=1, facecolors=cm.plasma(c/np.amax(c)), alpha=0.22, linewidth=1)
m = cm.ScalarMappable(cmap=cm.plasma)
m.set_array(c)
plt.colorbar(m)
#Show the plot.
plt.show()
生成的情节:
有人可以帮我看看这是怎么回事吗?
提前感谢您的帮助!
【问题讨论】:
-
请不要循环:
c[0, :] = 100等 — 也可以尝试c[:10, :] = 100并看到一根杆子呈现黄色 — 这是answer below 中概述的问题,您必须了解@987654328 @2D数组位置映射到球体上,数组的哪一部分没有映射到球体上的网格 -
啊,它是一个unit sphere,而不是一个unity球体...
-
感谢您的评论@gboffi!我更正了统一 --> 单位。
标签: python matplotlib plot visualization heatmap