c - 找不到带有 CATALINA 的 qt 或 x11 终端 gnuplot
问题描述
我用 Catalina 10.15.13 在我的 Macbook 上安装了 gnuplot。当我在 Xcode 中使用它时,它没有显示任何东西,它提供了
警告:使用“未知”终端进行绘图。
不会产生任何输出。请选择带有“设置终端”的终端。
话虽如此,我看到要绘制我没有的终端 qt 或 x11 所需的数据。问题有两个:
我该如何安装它们?自制软件不允许我使用 brew “安装 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,您可以执行以下任何操作:
方法一
只需输入gnuplot
终端,您将收到上面显示的消息和提示gnuplot>
。然后键入绘图命令并quit
在完成时键入。
方法二
在命令之后直接键入您的绘图命令,如下gnuplot
所示:
gnuplot -p -e "plot sin(x)"
方法三
将您的绘图命令放在一个脚本中,plot.cmds
如下所示:
plot sin(x)
然后告诉gnuplot
运行该脚本:
gnuplot -p -c plot.cmds
关键词:macOS、Catalina、gnuplot、Qt、GNUTERM
推荐阅读
- flutter - 为什么我不能在放大颤动中访问我的 s3 对象?
- cucumber - 黄瓜报告json文件问题
- asp.net - ObjectDataSource 找不到具有参数的非泛型方法
- reactjs - 除了为类名分配本地或在 create-react-app 中使用模块之外,css 导入名称的替代方案
- r - rowMeans 不适用于我的数据 - 所有向量都是数字
- redis - 使用内联 redis-cli 命令取消注册 RedisGears 注册会导致“ERR 未知命令 `RG_UNREGISTER`”
- python - AttributeError:模块“delivery.models.order_timelocation”没有属性“_meta”
- android - 错误状态:DocumentSnapshotPlatform 中不存在字段。(StreamBuilder 有问题)
- kubernetes - 防止容器内的OOM
- javascript - 我的网站在 chrome 上的欺骗性网站提前警告