Python 如何使用matplotlib打印非矩形二维数据?

Python 如何使用matplotlib打印非矩形二维数据?,python,matplotlib,plot,map-projections,Python,Matplotlib,Plot,Map Projections,我正在用Python进行一个计算,计算对象的物理属性,角度范围为0

我正在用Python进行一个计算,计算对象的物理属性,角度范围为0<θ<π/2和0<φ<π/2(即第一个八分之一)。要可视化特性,我当前正在将它们打印为三维单位球体上的颜色值。以合理的分辨率绘制此图是一个相当耗费资源的过程,但我不想从任何其他角度来看此图

我想创建的是一个2D图像绘图,与
imshow
创建的类似,只是它应该有一个球体八分之一的三角形轮廓投影到2D中。请注意,我不是问如何将3D数据投影到2D,而是问如何以类似于从θ=π/4,φ=π/4查看的球体八分之一的方式显示2D数据

我现在的代码如下。具体细节可能与答案不太相关,但它给出了我试图做什么的想法

'''
The code above this point produces three arrays stored in a dictionary 
called phs with the three entries using the keys 'I', 'II', 'III.  Each 
array is a function of theta and phi where 
theta = np.linspace( 0, 90, nPoints)
phi = np.linspace( 0, 90, nPoints)
also 
types = ('I', 'II', 'III')  
'''

# Colormaps
mx = np.maximum( np.maximum( phs['I'], phs['II']), phs['III'])
cmap = cm.ScalarMappable( cmap='BuPu')
cmap.set_array( mx)
clrs = dict()
for type in types:
    clrs[type] = cmap.to_rgba( phs[type])

# Convert to Cartesian coordinates with unit radius
xM, yM, zM = plotCartesianFixedR( thetaM, phiM)

# Plot
fig = plt.figure( figsize=(16,7))
ax = dict()
ax['I'] = plt.subplot( 131, projection='3d')
ax['II'] = plt.subplot( 132, projection='3d')
ax['III'] = plt.subplot( 133, projection='3d')
surf = dict()
for type in types:
    surf[type] = ax[type].plot_surface( xM, yM, zM, rstride=1, cstride=1, 
            facecolors=clrs[type], shade=False)
    # Set axis properties
    ax[type].set_xticklabels([])
    ax[type].set_yticklabels([])
    ax[type].set_zticklabels([])
    ax[type].view_init(elev=45, azim=45)

# Colorbar
plt.colorbar( cmap, shrink=1)
ax['I'].set_title( 'Log$_{10}(|\Delta k|)$ Type I (ssf)')
ax['II'].set_title( 'Log$_{10}(|\Delta k|)$ Type II (sff)')
ax['III'].set_title( 'Log$_{10}(|\Delta k|)$ Type III (fsf)')

# Add title
if title:
    plt.suptitle(title)
输出如下所示:


只是为了重申这个问题;我想复制这个情节几乎完全,但在二维不包括背景轴

关于你的项目,你有什么特别的问题吗?另外,请注意,不会有一个“正确”的解决方案,因为有。@Carsten计算投影不是我的问题。问题是如何在python中将其显示为2D绘图,因为它不再具有
imshow
或类似例程所期望的矩形网格。“图像”的轮廓是一个凸起的三角形,如上图所示。请重新表述问题以解决实际问题(即使用matplotlib绘制非矩形数据)?因为要回答你的问题,正如现在所说的,还需要做投影。@Carsten好建议。现在更好了?制作一个透明(或白色等)位图,将x、y坐标值插入其中,然后
imshow
显示。