Can't find qt or x11 terminal gnuplot with CATALINA

∥☆過路亽.° 提交于 2020-04-07 07:34:21

问题


I installed gnuplot on my Macbook with Catalina 10.15.13. When I use it in Xcode it does not show me anything, it provides

WARNING: Plotting with an 'unknown' terminal.

No output will be generated. Please select a terminal with 'set terminal'.

Having said that, I saw that to plot data I would need of the terminals qt or x11 which I do not have. The questions are two:

  1. How can I install them? homebrew does not allow me to use brew "install gnuplot --with-x11"

  2. In order to see the data, Do I have to need of this two terminals? Can't I use another one?

What I'm asked to do is to call gnuplot inside my program, and not controlling it from the terminal. It works, but it does not keep thw window with chart open. Inside utils.h there are some function and the structure instance, but it does not have nothing to do with gnuplot. My code is:

#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;

}


回答1:


I tried the following on macOS Catalina and it works fine:

# Remove existing stuff to be sure my technique really works!
brew rm qt gnuplot

# Install qt and gnuplot afresh
brew install qt gnuplot

Then, in Terminal, or preferably in your login script so it is set every time you login:

export GNUTERM=qt

Now you can use 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)


I don't understand how you are using gnuplot. AFAIK, you can do any of the following:

Method 1

Simply type gnuplot in Terminal, and you will get the messages shown above and the prompt gnuplot>. You then type your plotting commands and type quit when you are finished.

Method 2

Type your plotting commands directly following the gnuplot command like this:

gnuplot -p -e "plot sin(x)"

Method 3

Put your plotting commands in a script called plot.cmds like this:

plot sin(x)

Then tell gnuplot to run that script:

gnuplot -p -c plot.cmds

Keywords: macOS, Catalina, gnuplot, Qt, GNUTERM



来源:https://stackoverflow.com/questions/60820836/cant-find-qt-or-x11-terminal-gnuplot-with-catalina

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!