4

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!

2
  • I think you want to add a drawnow at the end of your script (after plot) Commented Jun 22, 2018 at 15:10
  • Either drawnow or adding a pause solve my problem. Thanks! Commented Jun 23, 2018 at 18:23

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I used your solution this past week (specifically, something along the lines of pause(0.1)). It seems to me that drawnow is slightly more elegant; is there any reason to use pause instead of drawnow?
@terikin those functions do different things. pause without an argument, waits until something happens, which prevents the plot from disappearing. The function drawnow will force the plotting before continuing (in your case, exiting the program). The only reason drawnow works for you is that you have the terminal scroll. But if the plot was on a separate window or if the terminal window closed after the program (or a pager too, not sure), then you would see a difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.