Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inject colors in graphs generated by gnuplot in term dumb plot mode

I use gnuplot in dumb plot mode (plot directly in terminal) to build monitoring tools in command line. I would like to add colors to my graphs.

Here is a simple view:

> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'"

100 +-+-------+---------+---------+---------+---------+-------+-@
    +         +         +         +         +         +         +
 90 +-+                                         'file1'    @  +-+
 80 +-+                                     @                 +-+
    |                                                           |
 70 +-+                                @                      +-+
    |                                                           |
 60 +-+                           @                           +-+
 50 +-+                      @                                +-+
    |                                                           |
 40 +-+                 @                                     +-+
    |                                                           |
 30 +-+            @                                          +-+
 20 +-+       @                                               +-+
    +         +         +         +         +         +         +
 10 +-+--@----+---------+---------+---------+---------+-------+-+
    0         10        20        30        40        50        60

with file1:

5 10
10 20
15 30
20 40
25 50
30 60
35 70
40 80
50 90
60 100

My attempt to add colors:

> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" |
           sed 's|@|\\\033[31m@\\\033[0m|g' | cat -v

100 +-+-------+---------+---------+---------+---------+-------+-\@33[31m@\@33[0m
    +         +         +         +         +         +         +
 90 +-+                                         'file1'    \@33[31m@\@33[0m  +-+
 80 +-+                                     \@33[31m@\@33[0m                 +-+
    |                                                           |
 70 +-+                                \@33[31m@\@33[0m                      +-+
    |                                                           |
 60 +-+                           \@33[31m@\@33[0m                           +-+
 50 +-+                      \@33[31m@\@33[0m                                +-+
    |                                                           |
 40 +-+                 \@33[31m@\@33[0m                                     +-+
    |                                                           |
 30 +-+            \@33[31m@\@33[0m                                          +-+
 20 +-+       \@33[31m@\@33[0m                                               +-+
    +         +         +         +         +         +         +
 10 +-+--\@33[31m@\@33[0m----+---------+---------+---------+---------+-------+-+
    0         10        20        30        40        50        60
like image 930
jyvet Avatar asked Apr 19 '16 21:04

jyvet


1 Answers

Solution 1

Use grep --colors=always <pattern>, it uses grep default color highlighting.

> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" |
           grep --color=always '@'

Solution 2

Use colout <pattern> <color>. It has the ability to select the color but a python library has to be installed (pip install colout).

> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" | colout '@' green
like image 123
jyvet Avatar answered Oct 30 '22 14:10

jyvet