cpp 代码中的 gnuplot - 无法显示图形
Gnuplot in cpp code - Graphics can not be show
我在cpp代码中使用了gnuplot。我从指南中获取代码。我调整了这段代码没有错误,但图形无法显示。
法典:
#define GNUPLOT "gnuplot -persist"
int main(int argc, char **argv)
{
FILE *gp;
gp = popen(GNUPLOT,"w"); /* ’gp’ is the pipe descriptor */
if (gp==NULL)
{
printf("Error opening pipe to GNU plot. Check if you have it! n");
return 0;
}
fprintf(gp, "set samples 2000n");
fprintf(gp, "plot cos(x) n");
fprintf(gp, "rep sin(x) n");
fclose(gp);
return 0;
}
编辑 1
我尝试了另一个指南中的示例。我编译并运行它们没有错误,但图表没有出现。我使用Linux操作系统。
代码 2 :
#include <stdio.h>
#include <plot.h>
#include <math.h>
#define SIZE 100.0 /* nominal size of user coordinate frame */
#define EXPAND 2.2 /* expansion factor for elliptical box */
void draw_boxed_string (plPlotter *plotter,
char *s, double size, double angle)
{
double true_size, width;
pl_ftextangle_r (plotter, angle); /* set text angle (degrees) */
true_size = pl_ffontsize_r (plotter, size); /* set font size */
width = pl_flabelwidth_r (plotter, s); /* compute width of string */
pl_fellipserel_r (plotter, 0.0, 0.0,
EXPAND * 0.5 * width, EXPAND * 0.5 * true_size,
angle); /* draw surrounding ellipse */
pl_alabel_r (plotter, 'c', 'c', s); /* draw centered text string */
}
int main()
{
plPlotter *plotter;
plPlotterParams *plotter_params;
int i;
/* set a Plotter parameter */
plotter_params = pl_newplparams ();
pl_setplparam (plotter_params, "PAGESIZE", "letter");
/* create a Postscript Plotter that writes to standard output */
if ((plotter = pl_newpl_r ("ps", stdin, stdout, stderr,
plotter_params)) == NULL)
{
fprintf (stderr, "Couldn't create Plottern");
return 1;
}
if (pl_openpl_r (plotter) < 0) /* open Plotter */
{
fprintf (stderr, "Couldn't open Plottern");
return 1;
}
/* specify user coor system */
pl_fspace_r (plotter, -(SIZE), -(SIZE), SIZE, SIZE);
pl_pencolorname_r (plotter, "blue"); /* use blue pen */
pl_fillcolorname_r (plotter, "white"); /* set white fill color */
pl_filltype_r (plotter, 1); /* fill ellipses with fill color */
/* choose a Postscript font */
pl_fontname_r (plotter, "NewCenturySchlbk-Roman");
for (i = 80; i > 1; i--) /* loop through angles */
{
double theta, radius;
theta = 0.5 * (double)i; /* theta is in radians */
radius = SIZE / pow (theta, 0.35); /* this yields a spiral */
pl_fmove_r (plotter, radius * cos (theta), radius * sin (theta));
draw_boxed_string (plotter, "GNU libplot!", 0.04 * radius,
(180.0 * theta / M_PI) - 90.0);
}
if (pl_closepl_r (plotter) < 0) /* close Plotter */
{
fprintf (stderr, "Couldn't close Plottern");
return 1;
}
if (pl_deletepl_r (plotter) < 0) /* delete Plotter */
{
fprintf (stderr, "Couldn't delete Plottern");
return 1;
}
return 0;
}
你不仅应该运行./plot > a.ps
./plot
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 程序崩溃并显示"std::out_of_range"错误
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 从数据库实时显示QT c++中的数据
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- 显示错误输出的简单数组排序程序
- Qt自定义QPush按钮未显示在布局上
- C++射线示踪剂ppm表示没有足够的数据来显示图像
- 显示基于用户输入的整数的字符
- 使用QTreeView,如何通过调用函数只突出显示特定的行/列
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 如何使 windows 命令提示符在C++可执行文件上显示返回值?
- 密码登录程序将永远循环并显示不正确的结果
- std::strftime 在 Windows 中使用 GMTIME 将时区 UTC 显示为 UTC+1