1

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;

}

Community
  • 1
  • 1
  • Possibly related: https://stackoverflow.com/questions/32086405/warning-plotting-with-an-unknown-terminal-no-output-will-be-generated-pleas – halfer Mar 23 '20 at 20:18

1 Answers1

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)

enter image description here


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

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • 1
    where should I use "export GNUTERM=qt"? – Massimiliano Lorenzin Mar 24 '20 at 23:37
  • You need to do the `export` at some point before you use `gnuplot`. Most people do it in their login script, e.g. `$HOME/.profile` for `bash` users. – Mark Setchell Mar 25 '20 at 07:49
  • sorry ( I'm a rookie). Do I write it in the terminal? – Massimiliano Lorenzin Mar 25 '20 at 12:12
  • 1
    Yes, that will work, but you will have to do it again each time you login before using `gnuplot` – Mark Setchell Mar 25 '20 at 12:22
  • Ok Thank you. It works. I add two steps during the unistalling: 1- brew uninstall gnuplot 2- rm '/usr/local/bin/gnuplot' 3- brew link --overwrite gnuplot after these three steps your procedure works fine. Thank you. Do you know how to keep the window open? When I run the code, the chart is leanched, I see it for less than a second and then it closes immediatly. – Massimiliano Lorenzin Mar 25 '20 at 13:43
  • 1
    I think you want to persist the plot, like this `gnuplot -p -e "plot sin(x)"` Or, if you have a script file `gnuplot -p -c plot.cmds` – Mark Setchell Mar 25 '20 at 14:07
  • always from terminal? Because I'm plotting the data from a file c, and i call the gnuplot from the file with the function open("path,"w"). I also specify the commands from there. – Massimiliano Lorenzin Mar 25 '20 at 14:49
  • 1
    I have updated my answer to try and clarify things - so please read it through again. If you are using `gnuplot` some other way, please click `edit` under your own original question and show what you are trying to do there. Thank you. – Mark Setchell Mar 25 '20 at 14:59
  • ok I tried in your way, it works, and the windows stay open, but it 's not what i'm looking for. I read the date from a file in input ( that ofter change) I elaborate them and then I'm supposed to print them with gnuplot. – Massimiliano Lorenzin Mar 25 '20 at 17:29
  • 1
    Try `popen("/usr/local/bin/gnuplot -p"` – Mark Setchell Mar 25 '20 at 17:45
  • It works! Its stays open! really thank you for your patience! – Massimiliano Lorenzin Mar 25 '20 at 17:47
  • You're welcome - sorry it took longer than usual. We were all beginners once, and kind folk helped us and so it goes on... Good luck with your project and come back if you get stuck - new questions (and answers) are free! – Mark Setchell Mar 25 '20 at 17:50
  • 'where should I use "export GNUTERM=qt"?' Add "export GNUTERM=qt" without quotes to your ~/.bash_profile file, and use "source ~/.bash_profile" without quotes in a Terminal window to make it immediately active. – Roger Wehage May 29 '21 at 13:16