1 回答
TA贡献1816条经验 获得超4个赞
一种方法是用 使行长度相等np.repeat。仅当所有行的长度都是最长行长度的除数时,这才有效。
数据建议使用LogNorm,尽管这样的规范会因样本输入中的零而分心。
一些代码来说明这个想法:
from matplotlib import pyplot as plt
from matplotlib import colors as mcolors
import numpy as np
results = [np.array([6.06674849e-18, 2.28597646e-03]),
np.array([0.02039694, 0.01245901, 0.01264321, 0.00963068]),
np.array([2.28719585e-18, 5.14800709e-02, 2.90957713e-02, 0.00000000e+00,
4.22761202e-19, 3.21765246e-02, 8.86959187e-03, 0.00000000e+00])]
longest = max([len(row) for row in results])
equalized = np.array( [np.repeat(row, longest // len(row)) for row in results])
# equalized = np.where(equalized == 0, np.NaN, equalized)
norm = mcolors.LogNorm()
heatmap = plt.imshow(equalized, cmap='nipy_spectral', norm=norm, interpolation='nearest',
origin='lower', extent=[0, 6000, 0.5, len(results)+0.5])
plt.colorbar(heatmap)
plt.gca().set_aspect('auto')
plt.yticks(range(1, len(results) + 1))
plt.show()
另一个具有 7 个级别(随机数)的示例。输入生成为:
bands = 7 results = [np.random.uniform(0, 1, 2**i) for i in range(1, bands+1)]
添加回答
举报