在术语哑图模式下,在gnuplot生成的图形中注入颜色

jyv*_*vet 5 shell gnuplot colors

我用gnuplot在哑绘图模式(曲线直接在终端)建立在命令行监视工具。我想为图表添加颜色。

这是一个简单的视图:

> 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
Run Code Online (Sandbox Code Playgroud)

与file1:

5 10
10 20
15 30
20 40
25 50
30 60
35 70
40 80
50 90
60 100
Run Code Online (Sandbox Code Playgroud)

我尝试添加颜色:

> 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
Run Code Online (Sandbox Code Playgroud)

jyv*_*vet 5

解决方案1

使用grep --colors=always <pattern>,它使用grep默认颜色突出显示。

> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" |
           grep --color=always '@'
Run Code Online (Sandbox Code Playgroud)

解决方案2

使用colout <pattern> <color>。它具有选择颜色的能力,但必须安装python库(pip install colout)。

> gnuplot5 -e "set term dumb 70 20; plot 'file1' pt '@'" | colout '@' green
Run Code Online (Sandbox Code Playgroud)