绘制 3D 热图

问题描述 投票:0回答:1

我有一个大小为 (100,519,492) 的 3D 数组。我想绘制 3D 热图,其中颜色由数组值定义,位置由数组中的索引定义。我尝试过谷歌搜索,但还没有接近得到结果。

我本质上想绘制这个 2D 数据集 100 次,形成基于数组值着色的区域(在本例中,该值设置为 0-白色或红色-1):

我尝试遵循本指南:https://www.geeksforgeeks.org/3d-heatmap-in-python/,但我明白了

ValueError: shape mismatch: objects cannot be broadcast to a single shape.  Mismatch is between arg 0 with shape (492,) and arg 1 with shape (519,).
# importing required libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from pylab import *

x = np.arange(0,492) #Number of columns in my 3d data array
y = np.arange(0,519) # Number of rows
z = np.arange(0,100) # Number of 2D slices making the 3D array
colo = ODS_diff # ODS_diff is the 3D array
  
# creating figures
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
  
# setting color bar
color_map = cm.ScalarMappable(cmap=cm.Greens_r)
color_map.set_array(colo)
  
# creating the heatmap
ax.scatter(x, y, z, marker='s',
                 s=200, color='red')
plt.colorbar(colo)
  
# adding title and labels
ax.set_title("3D Heatmap")
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
  
# displaying plot
plt.show()
python matplotlib multidimensional-array heatmap
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.