1

E.g. the following command

gnuplot -e "splot [x=-3:3] [y=-3:3] sin(x)*cos(y)"

works perfectly fine on Windows 10 with GNUPLOT 5.4p5. But on my Debian Bullseye box with GNUPLOT 5.4p1 all I get is the following error:

line 0: undefined variable:

Running GNUPLOT without arguments and executing the same command from GNUPLOT command prompt works as expected; a window appears with the plot.

Is this some kind of command line parsing issue, or something to do with the character set/locale?

2
  • Have you tried replacing both " with '?
    – Cyrus
    Commented Oct 30, 2022 at 18:51
  • @Cyrus: yes, tried with single quotes -- same result.
    – huoneusto
    Commented Oct 31, 2022 at 8:06

2 Answers 2

2

Answering my own question since I finally figured out what the problem was: an UTF-8 non-breaking space sequence (c2 a0).

I ran the same command on another Debian Bullseye system and got slightly different result:

line 0: undefined function:  sin

This made it look even more suspicious, as the system is identical to the system I previously tried on. Also, the spurious space before sin suggests this is a parsing/character encoding related rather than wrong syntax or something.

I tried removing the space (and re-typing it) between ] and sin and that fixed the problem.

To confirm I wasn't insane, I copied terminal output into a text file log.txt:

% cat log.txt    
% gnuplot -e "splot [x=-3:3] [y=-3:3] sin(x)*cos(y)"
line 0: undefined function:  sin
% gnuplot -e "splot [x=-3:3] [y=-3:3] sin(x)*cos(y)"
(plot window appears and disappears)

And dumped it with hexdump:

% hexdump -C log.txt
00000000  25 20 67 6e 75 70 6c 6f  74 20 2d 65 20 22 73 70  |% gnuplot -e "sp|
00000010  6c 6f 74 20 5b 78 3d 2d  33 3a 33 5d 20 5b 79 3d  |lot [x=-3:3] [y=|
00000020  2d 33 3a 33 5d c2 a0 73  69 6e 28 78 29 2a 63 6f  |-3:3]..sin(x)*co|
00000030  73 28 79 29 22 0a 6c 69  6e 65 20 30 3a 20 75 6e  |s(y)".line 0: un|
00000040  64 65 66 69 6e 65 64 20  66 75 6e 63 74 69 6f 6e  |defined function|
00000050  3a 20 c2 a0 73 69 6e 0a  25 20 67 6e 75 70 6c 6f  |: ..sin.% gnuplo|
00000060  74 20 2d 65 20 22 73 70  6c 6f 74 20 5b 78 3d 2d  |t -e "splot [x=-|
00000070  33 3a 33 5d 20 5b 79 3d  2d 33 3a 33 5d 20 73 69  |3:3] [y=-3:3] si|
00000080  6e 28 78 29 2a 63 6f 73  28 79 29 22 0a           |n(x)*cos(y)".|
0000008d

Which helped to pinpoint the culprit:

00000020  .. .. .. .. .. c2 a0 ..
0

With your command and per the Gnuplot manual:

-e "command" tells gnuplot to execute that single command before continuing.

"Continuing" means that Gnuplot expects a file to be provided and waits for it. Adding a simple hyphen at the end of your command, makes Gnuplot understand that instead of an input file to load it should expect input from stdin. It also drops you in its interactive shell environment after executing the commands you gave it.

$ gnuplot -e "splot [x=-3:3] [y=-3:3] sin(x)*cos(y)" -
gnuplot> 

[I do not represent the plot output here to keep this post as light as can be.]

3
  • This would not explain the different behavior on Linux and Windows
    – huoneusto
    Commented Oct 31, 2022 at 12:21
  • @hueneusto: Participants on this forum are here for the reason nicely summed up by the forum's domain's name: unix.stackexchange.com. When interested in Windows, a better forum in the StackExchange family might be superuser.com. Also your post was not particularly strong or explicit about explaining the different behavior between Windows and Linux contexts. You mentioned Windows, but because it's irrelevant here I provided you with a solution to tackle the absence of a plot in a Linux environment.
    – Cbhihe
    Commented Oct 31, 2022 at 13:31
  • Yes, the forum name sums it up nicely, as you say. That's why I posted the question here in the first place, as the erratic behavior only manifested itself on Linux. Imo. Windows is not irrelevant here, because it serves as a frame of reference. But I could have described the problem more verbosely/precisely.
    – huoneusto
    Commented Oct 31, 2022 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .