4
votes

When running Octave in an interactive shell session, I know I can display character-mode / ASCII plots, as discussed here: Character-mode (shell) plots with Matlab / Octave?

My problem is that I'd like to have that kind of output when my octave script is run non-interactively. That is, I'd like to be able to run something like the following:

#!/usr/bin/octave -qf

plot(sin(0:7))

And have output along the lines of :

    1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
      >      +   ---+      +      +      +      +      >
      >      +---    |                                 >
      >     |         |                                >
      >    |           |                               >
  0.5 >+  |             |                             +>
      >   |             |                            | >
      >  |               |                           | >
      > |                 |                         |  >
      >|                   +                       |   >
    0 >+                    |                     |   +>
      >                      |                    |    >
      >                      |                   |     >
      >                       |                 +      >
      >                        |               |       >
      >                         |             |        >
 -0.5 >+                        |            |        +>
      >                          |           |         >
      >                           +---      |          >
      >                               --   |           >
      >      +      +      +      +     -+|     +      >
   -1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
      1      2      3      4      5      6      7      8

I get that output if I open octave in the ssh session and then, at the octave terminal, call my script:

octave:1> testplot.m

But what I really want to do is to call testplot.m from other bash scripts, such as:

$ ./testplot.m

or

$ octave testplot.m

Neither of which actually give any plot output.

I have noticed that the interactive session output seems to scale automatically with the size of my terminal window, so in that sense it depends on the session.

Thanks for any assistance!

Clarification - I know how to create plots with figure visibility turned off, but I'm trying to avoid having to separately download plot files.

I also discovered this thread: Command-line Unix ASCII-based charting / plotting tool, but eplot seemed to give me errors (likely user error, bad data formatting, etc, but I don't know for sure), and I'd prefer to keep things in octave - octave already does exactly what I want as long as I'm in an interactive session!

1
I think you want to add a drawnow at the end of your script (after plot)Andy
Either drawnow or adding a pause solve my problem. Thanks!terikin

1 Answers

2
votes

All you have to do is to add a pause at the end of your Octave script.

Thing is, your script is already displaying the plot at the end but the program ends right after you you call plot, so the program exits and you don't even notice the plot.

In the picture below, I added the setting of graphics_toolkit and gnuplot terminal type, not because it's needed for your problem, but because on my system the default plot would be different.

enter image description here