Plotting heatmap with Gnuplot in C++

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 12:37:43

You must use the image plotting style, just like done in the demo page you linked:

#include <vector>
#include <cmath>
#include <boost/tuple/tuple.hpp>
#include "gnuplot-iostream.h"

int main()
{
    float frame[4][4];
    for (int n=0; n<4; n++)
    {
        for (int m=0; m<4; m++)
        {
        frame[n][m]=n+m;
        }
    }
    Gnuplot gp;
    gp << "unset key\n";
    gp << "set autoscale fix\n";
    gp << "plot '-' with image\n";
    gp.send2d(frame);
    gp.flush();
}

I cannot test it right now, but that should do the trick. Maybe you need to change the set autoscale part to fit your needs. Using set autoscale fix uses tight ranges for all axes (x, y, and color).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!