在同一个 gnuplot 窗口中绘制多个数据集

发布于 2025-01-13 07:11:09 字数 771 浏览 2 评论 0原文

我有两个数据集(x,y1)和(x,y2),这是我从计算结果中得到的,并将这些文件写入“data1.tmp”和“data1.tmp”中。 “数据2.tmp”。我想使用这两个数据集在 Gnuplot 中进行绘图。

#include <iostream>
#include <cstdlib>

int main()
{
    FILE* gnupipe1, *gnupipe2;
    
    const char* GnuCommands1[] = {"set title \"v vs x\"","plot \'data1.tmp\' with lines"};
    const char* GnuCommands2[] = {"set title \"y vs x\"","plot \'data2.tmp\' with lines"};

    gnupipe1 = _popen("gnuplot -persistent","w");
    gnupipe2 = _popen("gnuplot -persistent", "w");

    for (int i = 0; i < 2; i++)
    {
        fprintf(gnupipe1,"%s\n",GnuCommands1[i]);
        fprintf(gnupipe2,"%s\n", GnuCommands2[i]);
    }
    return 0;
}

现在,当我运行程序时,两个窗口会显示准确绘制数据。

如何以这种方式绘制多个数据集?说 (x,y1) & (x,y2) 在同一窗口中?

I have two data set (x,y1) and (x,y2) which I got from the result of computation and wrote those files in "data1.tmp" & "data2.tmp". I want to use this two data set to plot in Gnuplot.

#include <iostream>
#include <cstdlib>

int main()
{
    FILE* gnupipe1, *gnupipe2;
    
    const char* GnuCommands1[] = {"set title \"v vs x\"","plot \'data1.tmp\' with lines"};
    const char* GnuCommands2[] = {"set title \"y vs x\"","plot \'data2.tmp\' with lines"};

    gnupipe1 = _popen("gnuplot -persistent","w");
    gnupipe2 = _popen("gnuplot -persistent", "w");

    for (int i = 0; i < 2; i++)
    {
        fprintf(gnupipe1,"%s\n",GnuCommands1[i]);
        fprintf(gnupipe2,"%s\n", GnuCommands2[i]);
    }
    return 0;
}

Now when I run the program two window shows up plotting the data accurately.

How to plot multiple data set this way? say (x,y1) & (x,y2) in same window?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼性发作 2025-01-20 07:11:10

您正在打开两个不同的 gnuplot,您不需要这样做。

#include <iostream>
#include <cstdlib>

int main()
{
    FILE* gnupipe1;
    
    const char* GnuCommands1[] = {"set title \"v vs x\"",
                 "plot \'data1.tmp\' with lines, \'data2.tmp\' with lines"};

    gnupipe1 = _popen("gnuplot -persistent","w");

    for (int i = 0; i < 2; i++)
        fprintf(gnupipe1,"%s\n",GnuCommands1[i]);

    return 0;
}

You are opening two different gnuplots, you don't need to do that.

#include <iostream>
#include <cstdlib>

int main()
{
    FILE* gnupipe1;
    
    const char* GnuCommands1[] = {"set title \"v vs x\"",
                 "plot \'data1.tmp\' with lines, \'data2.tmp\' with lines"};

    gnupipe1 = _popen("gnuplot -persistent","w");

    for (int i = 0; i < 2; i++)
        fprintf(gnupipe1,"%s\n",GnuCommands1[i]);

    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文