Character-mode (shell) plots with Matlab / Octave?

后端 未结 3 2044
无人及你
无人及你 2020-12-06 18:56

This is maybe a bit odd question, but anyway. Sometimes, I am using ssh into servers or laboratory computers all over the place (continent) in order to check stuff and somet

3条回答
  •  不思量自难忘°
    2020-12-06 19:34

    Although there are many partial answers to this question, the only thing that worked for me on Windows via WSL & Cygwin was the following.

    1. 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:

    • Character-mode (shell/ASCII) plots with Octave scripts
    • Character-mode (shell) plots with Matlab / Octave?
    • Getting octave to plot when invoking a function from the command line
    • Command-line Unix ASCII-based charting / plotting tool
    • Print Plot in Octave in Background

    1. 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.

    1. 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);"
    

提交回复
热议问题