[英]4D plot surface does'nt display the colors of my 4th dimension
I've been trying de plot 4D figures of aerosols emissions in the atmosphere with X = Longitude, Y = latitude, Z = Injection Heigh of aerosols and cbar = Emissions quantity.我一直在尝试 de plot 大气中气溶胶排放的 4D 图,X = 经度,Y = 纬度,Z = 气溶胶注入高度和 cbar = 排放量。
The following lines do the job but the cbar datas seems to be 0 everywhere.以下几行完成了这项工作,但 cbar 数据似乎到处都是 0。
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
X, Y = np.meshgrid(lons2,lats2)
Z = Inj
C=Emi
scamap = plt.cm.ScalarMappable(cmap='inferno')
fcolors = scamap.to_rgba(C)
ax.plot_surface(X, Y, Z, facecolors=fcolors, cmap='inferno')
norm = mpl.colors.Normalize(vmin=0, vmax=10e-8)
fig.colorbar(scamap,norm=norm)
plt.show()
As you can see, it's all black.如您所见,它全是黑色的。
Do you have any suggestion, or another way to plot those data?您对 plot 这些数据有什么建议或其他方法吗? Maybe scatter could be a solution but I can't figure it out.
也许分散可能是一个解决方案,但我无法弄清楚。
Have a good day,祝你有美好的一天,
You need to normalize the colors, like this:您需要规范化 colors,如下所示:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.colors import Normalize
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
x = y = np.linspace(-2, 2)
X, Y = np.meshgrid(x, y)
Z = np.cos(X**2 + Y**2)
# color values
C = np.sqrt(X**2 + Y**2)
cmap = cm.inferno
norm = Normalize(vmin=np.amin(C), vmax=np.amax(C))
# create face colors from a colormap and normalized color values
fcolors = cmap(norm(C))
scamap = cm.ScalarMappable(cmap=cmap, norm=norm)
ax.plot_surface(X, Y, Z, facecolors=fcolors, cmap=cmap)
fig.colorbar(scamap)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.