为什么我的热图是空的(白色)

Why is my heatmap empty (white)?

本文关键字:白色 我的 为什么      更新时间:2023-10-16

我想画一个热图,我有一个二维数组,我遵循了这个答案:https://stackoverflow.com/a/32459287/2370139除了我在 c++ 中使用 gnuplot 并且我删除了"非均匀",因为第一行和列是常规值,而不是刻度。

Gnuplot gp;
gp << "set autoscale xfix n";
gp << "set autoscale yfix n";
gp << "set autoscale cbfix n";
gp << "plot '-' matrix with image notitlen";
gp.send2d(pmat);
gp.flush();

PMAT 是一个大小为 50*50 的 2D 数组。它填充了介于 0 和 1 之间的浮点值。它确实绘制了一个完美的白色网格,问题可能是什么?

注意:上述命令在带有文本文件的普通 gnuplot 终端中使用时工作正常,例如

0.5 0.3 0.3
0.2 0.4 0.6
0.2 0.8 1

所以问题必须来自我对C++ API 的使用

如果gnuplot-iostream没有对矩阵格式的二维数据的内置支持,则可以轻松地在代码中实现它。类似的东西

gp << "plot '-' matrix with image notitlen";
for (int i = 0; i < 50; ++i) {
    for (int j = 0; j < 50; ++j)
        gp << pmat[i][j] << "t";
    gp << "n";
}
gp.flush();

(未经测试)应该可以工作。