C++ 在C+中使用Gnuplot绘制热图+; #包括 #包括 #包括 #包括“gnuplot iostream.h” int main() { 浮动帧[4][4]; 对于(int n=0;n

C++ 在C+中使用Gnuplot绘制热图+; #包括 #包括 #包括 #包括“gnuplot iostream.h” int main() { 浮动帧[4][4]; 对于(int n=0;n,c++,gnuplot,heatmap,C++,Gnuplot,Heatmap,您必须使用图像打印样式,就像您链接的演示页面中所做的那样: #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;

您必须使用
图像
打印样式,就像您链接的演示页面中所做的那样:

#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 pm3d\n";
    gp << "set hidden3d\n";
    gp << "set view map\n";
    gp << "set xrange [ -0.500000 : 3.50000 ] \n";
    gp << "set yrange [ -0.500000 : 3.50000 ] \n";
    gp << "splot '-'\n";
    gp.send2d(frame);
    gp.flush();
}
#包括
#包括
#包括
#包括“gnuplot iostream.h”
int main()
{
浮动帧[4][4];

对于(int n=0;nHi!有一个问题。send2d()向gnuplot发送一个列。
图像不喜欢它,需要三个列。无论如何,用户通常也想传递x,y,颜色坐标。我也不确定send2d()如何传递知道浮点数组的大小。网站还声明应该避免使用简单数组,而更喜欢
std::vector
或类似的数组。Christoph,谢谢你的评论!我尝试过使用“send1d()”,但不知怎的,它起到了作用!但现在它只在关闭iostream管道后才显示图形。如果我想要replot,我必须关闭“Gnuplot”对象并创建一个新的,这将创建一个新的绘图窗口。似乎我需要一些终止或smth…@回答您是对的。我没有检查由
send2d()编写的格式。
。我想如果它适合splot,它也应该适合图像:)
#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();
}