Although there are many partial answers to this question, the only thing that worked for me on Windows via WSL & Cygwin was the following.
As an interactive CLI Session:
# Start the Octave CLI session:
octave-cli.exe -iWq
graphics_toolkit ("gnuplot")
x = -2*pi:2*pi;
y = sin(x);
figure(1,'Visible','off');
plot(y)
print (1, "-ddumb", "dummy"); type -q dummy.txt
Generating:
1 |-------------------------------------------------------------|
| + *** + + + ** * + + |
| ** * ** * |
| * * * * |
| * * * * |
0.5 |-+ * * * * +-|
| * * * * |
| * * * * |
| * * * * |
| * * * * |
0 |-+ * * * * +-|
| * * * |
| * * * |
| * * * |
| * * * |
-0.5 |-+ * * * * +-|
| * * * * |
| * * * * |
| **** * * * |
| + + *+* + + *+* |
-1 |-------------------------------------------------------------|
0 2 4 6 8 10 12 14
Unfortunately this is still dependent on using the temporary file dummy.txt
.
But the horribly bad Octave documentation doesn't provide any obvious alternatives, nor examples. At the end of an incomprehensible documentation read, you are far better off interpreting and guessing your way through the following related questions:
As a scripted CLI session:
$ cat foo.m
#!/usr/bin/env octave
graphics_toolkit ("gnuplot")
setenv GNUTERM dumb
x = -2*pi:2*pi;
y = sin(x);
plot(y)
pause (2);
Then run with: octave-cli foo.m
.
As a one-liner:
octave-cli.exe --eval "graphics_toolkit gnuplot;setenv GNUTERM dumb; plot(sin(-2*pi:2*pi)); pause(2)"
NOTE: The pause
is required to get any output!
If you are looking for other options to the print command (when using gnuplot), do the following:
gnuplot -e "set term"
gnuplot -e "set terminal dumb; plot sin(x);"
For example, in properly supported ANSI xterms, you can use sixel with:
gnuplot -e "set terminal sixelgd; plot sin(x);"