我在Macbook上使用Catalina 10.15.13安装了gnuplot。当我在Xcode中使用它时,它没有显示任何内容,它提供了
警告:使用“未知”终端进行绘图。
不会产生任何输出。请选择带有“设置终端”的终端。
话虽如此,我看到要绘制我没有的端子qt或x11所需的数据。问题是两个:
如何安装?自制软件不允许我使用brew“ install gnuplot --with-x11”
为了查看数据,我是否需要这两个终端?我不能再用一个吗?
我被要求做的是在程序中调用gnuplot,而不是从终端进行控制。它可以工作,但不能在打开图表的情况下保持窗口打开。在utils.h中,有一些函数和结构实例,但与gnuplot无关。我的代码是:
#include "utils.h"
#include <stdio.h>
char* commandsForGnuplot[] = {
"set style increment default",
"set title 'Simple Plots'",
"set title font ',20' norotate",
"set xrange[*:*] noreverse writeback",
"set x2range[*:*] noreverse writeback",
"set yrange[*:*] noreverse writeback",
"set y2range[*:*] noreverse writeback",
"set zrange[*:*] noreverse writeback",
"set cbrange[*:*] noreverse writeback",
"set rrange[*:*] noreverse writeback",
"plot[-pi / 2:pi] cos(x), -(sin(x) > sin(x + 1) ? sin(x) : sin(x + 1))"
};
int main(int argc, const char * argv[]) {
int n_commands = 11;
if ( argc < 2 ) { printf("Usage: %s -help for help\n", argv[0]); exit(1); }
if ( VERBOSE >= 2 ) { for (int a = 0; a < argc; a++) printf("%s ", argv[a]); printf("\n"); }
instance inst;
//////////////////////////////////////////////////////////
// Parse the command line
//////////////////////////////////////////////////////////
parse_command_line(argc,argv, &inst);
//printf(" file %s has %d non-empty lines\n", inst.input_file, number_of_nonempty_lines(inst.input_file)); exit(1);
//////////////////////////////////////////////////////////
// Parse the input file
//////////////////////////////////////////////////////////
read_input(&inst);
// if ( VRPopt(&inst) ) print_error(" error within VRPopt()");
// debug print
instance_tostring(&inst);
FILE* gnuplotPipe = popen("/usr/local/bin/gnuplot", "w");
if (!gnuplotPipe) { perror("popen gnuplot"); exit(EXIT_FAILURE); };
for (int i = 0; i < n_commands; i++)
{
fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]);
printf("%s \n", commandsForGnuplot[i]);
}
pclose(gnuplotPipe);
return 0;
}
我在macOS Catalina上尝试了以下操作,效果很好:
# Remove existing stuff to be sure my technique really works!
brew rm qt gnuplot
# Install qt and gnuplot afresh
brew install qt gnuplot
然后,在终端中,或者最好在您的登录脚本中,以便在您每次登录时进行设置:
export GNUTERM=qt
现在您可以使用 gnuplot
gnuplot
G N U P L O T
Version 5.2 patchlevel 8 last modified 2019-12-01
Copyright (C) 1986-1993, 1998, 2004, 2007-2019
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Terminal type is now 'qt'
Options are '0 font "Sans,9"'
gnuplot> plot sin(x)
我不明白你的使用方式gnuplot
。AFAIK,您可以执行以下任一操作:
方法1
只需键入gnuplot
Terminal,您将获得上面显示的消息和提示gnuplot>
。然后,键入绘图命令,并quit
在完成时键入。
方法2
直接在gnuplot
命令之后键入您的绘图命令,如下所示:
gnuplot -p -e "plot sin(x)"
方法3
将绘图命令放在如下脚本中plot.cmds
:
plot sin(x)
然后告诉gnuplot
运行该脚本:
gnuplot -p -c plot.cmds
关键字:macOS,Catalina,gnuplot,Qt,GNUTERM
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句