【问题标题】:Shell: How can I make a text-mode bar chart from parsed data (numbers)?Shell:如何从解析的数据(数字)制作文本模式条形图?
【发布时间】:2015-06-19 02:33:34
【问题描述】:

我正在开发一个 Linux 的 Bash shell 脚本,它从文本文件中提取数据,只留下 数字。 这些是我的示例解析数据:

3
4
4
5
6
7
8
8
9
11

我想创建一个简单的文本模式条形图,像这样,但对应于这些值:

详情:

  • 我需要垂直的图表。
  • 第一个数字应出现在左侧,最新的数字应出现在右侧
  • n(解析的数字)字符高列适合我。因此,在我的示例中,左边的第一个条应该是 3 个字符高,第二个是 4,第三个是 4,第四个是 5,依此类推。

更准确地说,对于这个例子,一些东西(使用character)像:

         █
         █
        ██ 
       ███
      ████
     █████
    ██████
   ███████
 █████████
██████████
██████████
██████████

注意第一列(左)高 3 个字符,最后一列(右)高 11 个字符。
$ 字符相同的示例,使其更具可读性:

         $
         $
        $$
       $$$
      $$$$
     $$$$$
    $$$$$$
   $$$$$$$
 $$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$

我所知道的最接近的是我的 进度条 方法,到目前为止,我已经在其他脚本中使用过:

printf "\033[48;5;21m"   # Blue background color
for i in $(seq 1 $n); do printf " "; done   # Create bar using blue spaces

这是:用n 空格填充每一行打印一个条。但是这个条是水平的,所以在这种情况下是不合适的。

我请求一些核心循环示例想法来创建此条形图。

在用户 Boardrider 的建议下,接受基于任何类 unix 工具的解决方案。 基于脚本语言(如 Perl 或 Python)的 Linux shell 解决方案也被接受,只要它们用于在许多设备上实现即可。

【问题讨论】:

  • 类 unix 的工具最适合这项任务吗?脚本语言不是更好的工具吗?
  • 好吧,@boardrider,我想在这种情况下使用 Bash shell。但如果这种条形图打印很困难,我可以考虑使用另一种语言。
  • 我必须承认你最初的建议是好的,@boardrider。我扩大了这个问题,允许任何 Linux shell 工具(不仅是 Bash),甚至是常用的 shell 脚本语言,如 Perl、Python...等。

标签: bash charts


【解决方案1】:

这是第一次和幼稚的尝试......这不是一个非常有效的解决方案,因为数据被解析了很多次,但它可能会有所帮助。在某种程度上,这是@Walter_A 提出的第一个循环想法。

#!/bin/sh
#
## building a vertical bar graph of data file
## https://stackoverflow.com/q/30929012
##
## 1. required. Data file with one value per line and nothing else!
## /!\ provide the (relative or absolute) file path, not file content
: ${1:?" Please provide a file name"}
test -e "$1" || { echo "Sorry, can't find $1" 1>&2 ; exit 2 ; }
test -r "$1" || { echo "Sorry, can't access $1" 1>&2 ; exit 2 ; }
test -f "$1" || { echo "Sorry, bad format file $1" 1>&2 ; exit 2 ; }
test $( grep -cv '^[0-9][0-9]*$' "$1" 2>/dev/null ) -ne 0 || { echo "Sorry, bad data in $1" 1>&2 ; exit 3 ; }
# setting characters
## 2. optional. Ploting character (default is Dollar sign)
## /!\ for blank color use "\033[48;5;21m \033[0m" or you'll mess...
c_dot="$2"
: ${c_dot:='$'}
## 3. optional. Separator characher (default is Dash sign)
## /!\ as Space is not tested there will be extra characters...
c_sep="$3"
: ${c_sep:='-'}
# init...
len_w=$(wc -l "$1" | cut -d ' ' -f 1 )
l_sep=''
while test "$len_w" -gt 0
do
        l_sep="${l_sep}${c_sep}";
        len_w=$(($len_w-1))
done
unset len_w
# part1: chart
echo ".${c_sep}${l_sep}${c_sep}."
len_h=$(sort -n "$1" | tail -n 1)
nbr_d=${#len_h}
while test "$len_h" -gt 0
do
        printf '| '
        for a_val in $(cat "$1")
        do
                test "$a_val" -ge "$len_h" && printf "$c_dot" || printf ' '
        done
        echo ' |'
        len_h=$(($len_h-1))
done
unset len_h
# part2: legend
echo "|${c_sep}${l_sep}${c_sep}|"
while test "$nbr_d" -gt 0
do
        printf '| '
        for a_val in $(cat "$1")
        do
                printf "%1s" $(echo "$a_val" | cut -c "$nbr_d")
        done
        echo ' |'
        nbr_d=$(($nbr_d-1))
done
unset nbr_d
# end
echo "'${c_sep}${l_sep}${c_sep}'"
unset c_sep
exit 0

编辑 1:这是对脚本的修改。它更正了分隔符处理(只需尝试使用 ' ' 或 '|' 作为第三个参数即可查看),但由于我使用参数编号而不是附加变量,它可能看起来不太可读。

编辑 2:它还处理负整数...您可以更改地面(第 5 个参数)

#!/bin/sh
#
## building a vertical bar graph of data file
## https://stackoverflow.com/q/30929012
##
## 1. required. Data file with one value per line and nothing else!
## /!\ provide the (relative or absolute) file path, not file content
: ${1:?" Please provide a file name"}
[ -e "$1" ] || { echo "Sorry, can't find $1" 1>&2 ; exit 2 ; }
[ -r "$1" ] || { echo "Sorry, can't access $1" 1>&2 ; exit 2 ; }
[ -f "$1" ] || { echo "Sorry, bad format file $1" 1>&2 ; exit 2 ; }
[ $( grep -cv '^[-0-9][0-9]*$' "$1" 2>/dev/null ) -ne 0 ] || { echo "Sorry, bad data in $1" 1>&2 ; exit 3 ; }
## /!\ following parameters should result to a single character
## /!\ for blank color use "\033[48;5;21m \033[0m" or you'll mess...
## 2. optional. Ploting character (default is Dollar sign)
## 3. optional. Horizontal border characher (default is Dash sign)
## 4. optional. Columns separator characher (default is Pipe sign)
## (!) however, when no arg provided the graph is just framed in a table
## 5. optional. Ground level integer value (default is Zero)
test "${5:-0}" -eq "${5:-0}" 2>/dev/null || { echo "oops, bad parameter $5" 1>&2 ; exit 3 ; }
# init...
_long=$(wc -l < "$1" ) # width : number of data/lines in file
if [ -n "$4" ]
then
        _long=$((_long*2-3))
fi
_line=''
while [ "$_long" -gt 0 ]
do
        _line="${_line}${3:--}"
        _long=$((_long-1))
done
unset _long
_from=$(sort -n "$1" | tail -n 1 ) # max int
_stop=$(sort -n "$1" | head -n 1 ) # min int

这种返工有两种形式。第一个产生与前一个类似的输出。

# begin
echo "${4-.}${3:--}${_line}${3:--}${4-.}"
# upper/positive
if [ $_from -gt ${5:-0} ]
then
        while [ $_from -gt ${5:-0} ]
        do
                printf "${4:-| }"
                for _cint in $(cat "$1" )
                do
                        if [ $_cint -ge $_from ]
                        then
                                printf "${2:-$}$4"
                        else
                                printf " $4"
                        fi
                done
                echo " ${4:-|}"
                _from=$((_from-1))
        done
        echo "${4-|}${3:--}${_line}${3:--}${4-|}"
fi
unset _from
# center/legend
_long=$(wc -L < "$1" ) # height : number of chararcters in longuest line...
while [ $_long -ge 0 ]
do
        printf "${4:-| }"
        for _cint in $(cat "$1" )
        do
                printf "%1s$4" $(echo "$_cint" | cut -c "$_long" )
        done
        echo " ${4:-|}"
        _long=$((_long-1))
done
unset _long
# lower/negative
if [ $_stop -lt ${5:-0} ]
then
        _from=${5:-0}
        echo "${4-|}${3:--}${_line}${3:--}${4-|}"
        while [ $_from -gt $_stop ]
        do
                printf "${4:-| }"
                for _cint in $(cat "$1" )
                do
                        if [ $_cint -lt $_from ]
                        then
                                printf "${2:-$}$4"
                        else
                                printf " $4"
                        fi
                done
                echo " ${4:-|}"
                _from=$((_from-1))
        done
fi
unset _stop
# end
echo "${4-'}${3:--}${_line}${3:--}${4-'}"
exit 0

注意:当所有值为正(在地面以上)或负(在地面以下)时,有两个检查以避免额外的循环! 好吧,也许我应该总是把“中心/传奇”部分放在最后?当首先有正值和负值时,它看起来有点难看,而当只有负整数时,标签不读取相反的内容并且带有令人不快的减号,这看起来很奇怪。
另请注意wc -L is not POSIX... ...因此可能需要另一个循环。

这是另一种变体,图例编号的大小正确,而不是底部。 这样做,我节省了一个额外的循环,但我不太喜欢输出(我更喜欢左侧的值而不是右侧的值,但这是一种品味,不是吗?)

# begin
printf "${4-.}${3:--}${_line}${3:--}${4-.}"
# upper/positive
if [ $_from -gt ${5:-0} ]
then
        echo ""
        while [ $_from -gt ${5:-0} ]
        do
                _ctxt=''
                printf "${4:-| }"
                for _cint in $(cat "$1" )
                do
                        if [ $_cint -ge $_from ]
                        then
                                printf "${2:-$}$4"
                        else
                                printf " $4"
                        fi
                        if [ $_cint -eq $_from ]
                        then
                                _ctxt="_ $_from"
                        fi
                done
                echo " ${4:-}${_ctxt}"
                _from=$((_from-1))
        done
        _from=$((_from+1))
else
        echo "_ ${1}"
fi
# center/ground
if [ $_stop -lt ${5:-0} ] && [ $_from -gt ${5:-0} ]
then
        echo "${4-|}${3:--}${_line}${3:--}${4-|}_ ${1}"
fi
# lower/negative
if [ $_stop -lt ${5:-0} ]
then
        _from=${5:-0}
        while [ $_from -gt $_stop ]
        do
                _ctxt=''
                printf "${4:-| }"
                for _cint in $(cat "$1" )
                do
                        if [ $_cint -lt $_from ]
                        then
                                printf "${2:-$}$4"
                        else
                                printf " $4"
                        fi
                        if [ $_cint -eq $((_from-1)) ]
                        then
                                _ctxt="_ $_cint"
                        fi
                done
                echo " ${4:-|}${_ctxt}"
                _from=$((_from-1))
        done
fi
# end
unset _from
printf "${4-'}${3:--}${_line}${3:--}${4-'}"
if [ $_stop -lt ${5:-0} ]
then
        echo ""
else
        echo "_ ${1}"
fi
unset _stop
exit 0

编辑 3:有一些额外的检查,因此当只有正数或负数时不会添加额外的接地线。

最后,我认为最终的解决方案是两者的混合,其中价值显示在侧面,价值的位置在中心。然后它更接近 GNU Plot 的输出。

# init...
_long=$(wc -l < "$1" )
if [ -n "$4" ]
then
        _long=$((_long*2-3))
fi
_line=''
while [ $_long -gt 0 ]
do
        _line="${_line}${3:--}"
        _long=$((_long-1))
done
unset _long
_from=$(sort -n "$1" | tail -n 1 ) # max int
_stop=$(sort -n "$1" | head -n 1 ) # min int
# begin
echo "${4-.}${3:--}${_line}${3:--}${4-.}"
# upper/positive
if [ $_from -gt ${5:-0} ]
then
        while [ $_from -gt ${5:-0} ]
        do
                _ctxt=''
                printf "${4:-| }"
                for _cint in $(cat "$1" )
                do
                        if [ $_cint -ge $_from ]
                        then
                                printf "${2:-$}$4"
                        else
                                printf " $4"
                        fi
                        if [ $_cint -eq $_from ]
                        then
                                _ctxt="_ $_from"
                        fi
                done
                echo " ${4:-|}$_ctxt"
                _from=$((_from-1))
        done
        echo "${4-|}${3:--}${_line}${3:--}${4-|}"
fi
# center/ground
_size=$(wc -l < "$1" ) # width : number of data/lines in file
##_long=${#_size} # height : number of chararcters in long
#_long=1
##while [ $_long -gt 0 ]
#while [ $_long -le ${#_size} ]
#do
       #_rank=1
       #printf "${4:-| }"
       #while [ $_rank -le $_size ]
       #do
               #printf "%1s$4" $( printf "%0${#_size}d" $_rank  | cut -c $_long )
               #_rank=$((_rank+1))
       #done
       #printf " ${4:-|}"
       ##_long=$((_long-1))
       #_long=$((_long+1))
       ##if [ $_long -eq 0 ]
       #if [ $_long -eq ${#_size} ]
       #then
               #printf "_ ${1}"
       #fi
       #echo ''
#done
_rank=1
printf "${4:-| }"
while [ $_rank -le $_size ]
do
        printf "%1s$4" $( expr "$_rank" : '.*\(.\)$' )
        _rank=$((_rank+1))
done
echo " ${4:-|}_ ${1}"
# lower/negative
if [ $_stop -lt ${5:-0} ]
then
        echo "${4-|}${3:--}${_line}${3:--}${4-|}"
        while [ $_from -gt $_stop ]
        do
                _ctxt=''
                printf "${4:-| }"
                for _cint in $(cat "$1" )
                do
                        if [ $_cint -lt $_from ]
                        then
                                printf "${2:-$}${4}"
                        else
                                printf " $4"
                        fi
                        if [ $_cint -eq $((_from-1)) ]
                        then
                                _ctxt="_ $_cint"
                        fi
                done
                echo " ${4:-|}$_ctxt"
                _from=$((_from-1))
        done
fi
unset _from
unset _stop
# end
echo "${4-'}${3:--}${_line}${3:--}${4-'}"
exit 0

最后的改进是扩展能力...

【讨论】:

  • 花式工作!谢谢你,吉尔杜克斯。既然我有一个纯粹的(或接近的)Bash 解决方案,我决定扩大这个问题,以允许任何 Linux shell 工具,甚至脚本语言,如 cmets 中所要求的。
  • @sopalajo-de-arrierez 这是一个 POSIX 解决方案(在 Debian 下使用 DAsh 进行测试,但 BAsh 在非交互地称为“sh”时主要符合 POSIX)“允许任何 Linux”是什么意思shell 工具,甚至是脚本语言”?
  • 我的意思是,我发现对于 shell 问题通常给出的答案适用于任何 shell、特定 shell、许多发行版中通常包含的工具(或者至少是最流行的工具,比如Ubuntu 或 Debian),用于必须下载(或编译)的开源工具,用于在许多 Linux(如 Perl 或 Python)上似乎被视为 POSIX 增强的广泛脚本语言,甚至(不那么常见)用于支付工具在外壳中工作。我同意 Unix Stack Exchange 的这种行为。我只指定了 BASH,因为在写 shell 时,有时有人会问。
  • 关于接受(“最佳”)答案的选择,这是一个模棱两可的问题。我更喜欢 POSIX 兼容,只要它们更具适应性。但有时单一的单行解决方案非常实用。我认为在 Stack Exchange 论坛上没有关于此的约定,但我会说......谁打扰?我们来这里是为了学习和建立维基目录,而不是为了获得声望。
  • 因为我们来这里是为了学习和建立一个维基目录,也因为我也有需要,所以我重新设计了最初的答案,以便制作一个更健壮的脚本和更具适应性的工具。这让我朝着我想分享的其他方向前进,所以我编辑了答案以放置所有 4 个表亲脚本:然后人们可以测试和改进。
【解决方案2】:

您可以安装专用的绘图工具... 我只知道 GNU-Plot,但它很大(有很多依赖项,包括 ImageMagick)

root@localhost: # apt-get install gnuplot-nox
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  fontconfig fontconfig-config fonts-droid fonts-liberation ghostscript groff
  gsfonts hicolor-icon-theme imagemagick imagemagick-common libcairo2 libcroco3
  libcupsimage2 libdatrie1 libdjvulibre-text libdjvulibre21 libexiv2-12 libffi5
  libfontconfig1 libgd2-noxpm libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common
  libglib2.0-0 libglib2.0-data libgs9 libgs9-common libice6 libijs-0.35
  libilmbase6 libjasper1 libjbig0 libjbig2dec0 libjpeg8 liblcms1 liblcms2-2
  liblensfun-data liblensfun0 liblqr-1-0 libltdl7 liblua5.1-0 libmagickcore5
  libmagickcore5-extra libmagickwand5 libnetpbm10 libopenexr6 libpango1.0-0
  libpaper-utils libpaper1 libpixman-1-0 libpng12-0 librsvg2-2 librsvg2-common
  libsm6 libthai-data libthai0 libtiff4 libwmf0.2-7 libxaw7 libxcb-render0
  libxcb-shm0 libxft2 libxmu6 libxpm4 libxrender1 libxt6 netpbm poppler-data
  psutils shared-mime-info ttf-dejavu-core ufraw-batch x11-common
Suggested packages:
  ghostscript-cups ghostscript-x hpijs gnuplot-doc imagemagick-doc autotrace
  cups-bsd lpr lprng curl enscript ffmpeg gimp gnuplot grads hp2xx html2ps
  libwmf-bin mplayer povray radiance sane-utils texlive-base-bin transfig
  xdg-utils exiv2 libgd-tools libjasper-runtime liblcms-utils liblcms2-utils
  ttf-baekmuk ttf-arphic-gbsn00lp ttf-arphic-bsmi00lp ttf-arphic-gkai00mp
  ttf-arphic-bkai00mp librsvg2-bin poppler-utils fonts-japanese-mincho
  fonts-ipafont-mincho fonts-japanese-gothic fonts-ipafont-gothic
  fonts-arphic-ukai fonts-arphic-uming fonts-unfonts-core ufraw
The following NEW packages will be installed:
  fontconfig fontconfig-config fonts-droid fonts-liberation ghostscript
  gnuplot-nox groff gsfonts hicolor-icon-theme imagemagick imagemagick-common
  libcairo2 libcroco3 libcupsimage2 libdatrie1 libdjvulibre-text libdjvulibre21
  libexiv2-12 libffi5 libfontconfig1 libgd2-noxpm libgdk-pixbuf2.0-0
  libgdk-pixbuf2.0-common libglib2.0-0 libglib2.0-data libgs9 libgs9-common
  libice6 libijs-0.35 libilmbase6 libjasper1 libjbig0 libjbig2dec0 libjpeg8
  liblcms1 liblcms2-2 liblensfun-data liblensfun0 liblqr-1-0 libltdl7 liblua5.1-0
  libmagickcore5 libmagickcore5-extra libmagickwand5 libnetpbm10 libopenexr6
  libpango1.0-0 libpaper-utils libpaper1 libpixman-1-0 libpng12-0 librsvg2-2
  librsvg2-common libsm6 libthai-data libthai0 libtiff4 libwmf0.2-7 libxaw7
  libxcb-render0 libxcb-shm0 libxft2 libxmu6 libxpm4 libxrender1 libxt6 netpbm
  poppler-data psutils shared-mime-info ttf-dejavu-core ufraw-batch x11-common
0 upgraded, 73 newly installed, 0 to remove and 0 not upgraded.
Need to get 38.3 MB of archives.
After this operation, 111 MB of additional disk space will be used.
Do you want to continue [Y/n]?

(要求“gnuplot”提供相同的包加上“gnuplot-nox”) 安装后,我会使用一个名为 data 的数据文件进行交互检查:

Terminal type set to 'unknown'
gnuplot>  set term dumb
Terminal type set to 'dumb'
Options are 'feed size 79, 24'
gnuplot> plot data
undefined variable: data
gnuplot> plot "data"
gnuplot> # nice ASCII-chart not shown here, curve of "A"
gnuplot> set style data histogram
gnuplot> plot "data"
gnuplot> # nice ASCII-chart not shown here, bars of "**"
gnuplot> quit

如需快速入门,请查看this lowrank.net page 然后histograms demo
最后,使用here 加上here 编写野兽脚本
例如:

#!/bin/sh
#
_max=$(sort -n "$1" | tail -n 1)
_min=$(sort -n "$1" | head -n 1)
_nbr=$(wc -l < "$1" )
gnuplot << EOF
set terminal dumb ${COLUMNS:-$(tput cols)},${LINES:-$(tput lines)}
set style data histogram
set xrange[-1:$(_nbr+1)]
set yrange[$(_min-3):$(_max+2)]
set xlabel "something to display below horizontal axis"
plot "$1" title "a nice title in the corner instead of filename"
EOF

只需更改选项即可将真实图形输出到文件中。
当设置的选项很少时:

#!/bin/sh
#
gnuplot -e "set terminal dumb; set style data histogram; plot '$1' "

如果要绘制的数据很少,与 shell 脚本相比,它可能看起来有点矫枉过正。 但是使用这样的工具对于大量数据变得非常有用(它运行得更快) 或者有一些变化(GNUPlot 转义空白行,绘制正负整数和小数,使用多字段文件,在同一个图中合并许多文件或列)
最后,有一个 Ruby 包装器可以传递给它:eplot ;和另一个看起来更简单的 Perl 前端:feedgnuplot

编辑:默认情况下,它使用屏幕大小减去边距...

【讨论】:

  • 一个非常完整的解决方案。它需要 X-Windows 是多么可悲啊。无论如何,谢谢,很多人会发现它很有用。
  • 不,不... 一些 X 库是必需的(那些与字体相关的),因为它们被某些图像格式使用,因为 GNU Plot 可以输出几乎任何格式(我认为它使用 Image Magic 来执行转换)我在没有 X 窗口系统的盒子中测试它,安装后不再有 X(Debian 的 gnuplot-nox)
【解决方案3】:

我觉得可以简单一点...

#!/bin/bash

# Asume the data is in a textfile "/tmp/testdata.txt". One value per line.

MAXVALUE=$( sort -nr /tmp/testdata.txt | head -n1 )     # get the highest value
CHARTHEIGHT=$MAXVALUE                                   # use it for height of chart 
                                                        # (can be other value)
CHARTLINE=$CHARTHEIGHT                                  # variable used to parse the lines

while [ $CHARTLINE -gt 0 ]; do                          # start the first line
    (( CHARTLINE-- ))                                    
    REDUCTION=$(( $MAXVALUE*$CHARTLINE/$CHARTHEIGHT ))  # subtract this from the VALUE
    while read VALUE; do
        VALUE=$(( $VALUE-$REDUCTION ))
        if [ $VALUE -le 0 ]; then                       # check new VALUE
             echo -n "    " 
        else
             echo -n "▓▓▓ "
        fi
    done < /tmp/testdata.txt
    echo
done
echo
exit

此脚本将解析每一行数据,减少读取值并检查是否有剩余内容。如果是,则显示一个块;如果没有,显示一个空格。使用不同的 REDUCTION 值重复每一行。 脚本可以扩展为包括图例、颜色、半/四分之一块等...

除了 SORT 和 HEAD 都在 BASH 命令中

【讨论】:

    【解决方案4】:

    循环想法1: 搜索最高数字并记住 nr 行。
    以 value=最高数字开始,检查所有值-ge ${value}。这些将被填充,其他空间。下一行你使用(( value = value - 1 ))
    效率不高,您将多次遍历解析的数据。

    循环想法 2: 从您的数据中创建诸如“xxx”和“xxxxxxxx”之类的字符串(并记住最大值)。你有你的图表水平) 使用 printf 格式为每行添加空格(您有一个所有行长度相同的文件) 搜索一种方法来旋转您的文件。

    循环想法 3: 当您有 k 个值且 m 为最大值时,首先创建一个文件 m 行 k 个连续数字 (1 2 3 ...),并以空格结束。
    循环遍历这些值并在正确的位置用“x”替换数字。 对于第 3 行中的值 6,这将类似于

    (( replace_from = m - 5 ))
    sed -i ${replace_from}',$ s/ 6 / x /g' myfile
    

    循环后用空格替换所有数字。

    【讨论】:

      【解决方案5】:

      有许多 Python 图形库。 Python plotting libraries 列出了其中的大部分。 但是我认为它们是面向X的... 但是有些人为控制台/终端编写了替代解决方案。我找到了两个:

      • pysparklines 和它的老 spark 使用 Unicode 字符绘制小的输入直方图(所以它很好但有限,因为它是单行,并且在使用 UTF-8 的 X 下呈现更好)
      • bashplotlib - 尽管它的名字是一个 pythonic 集合,它可以在纯终端/控制台中以类似于 Gnuplot 的方式绘制直方图和散点图。

      【讨论】:

      • 他们看起来都很有前途,Gildux。我建议您将它们划分为两个不同的答案。而且,根据规则,您应该添加一些简单的安装过程(我无法找到它的pysparklines)和/或使用信息/示例。
      • 对于pysparklines,我只使用了pip install pysparklines 命令是sparkline,后跟整数列表(因为它们在data 文件中,我使用sparkline &lt; data,正如我所提到的,结果是带有 unicode 字符的单行(在我没有 X 的框中,有些字符是方框)
      • 对于bashplotlib,我还使用pip install bashplotlib 安装了命令是histscatter,但我无法让它工作:ImportError: No module named bashplotlib.histogram 好的,谷歌搜索后,it should be installed from source 然后,我去了project home并下载了源zip...之后:pip unstall bashplotlib; unzip bashplotlib-master.zip; cd bashplotlib-master; python setup.py install我可以尝试:hist --file data
      • 感谢您提供的信息,Gildux。事实上,spark 命令在没有 X Windows 的情况下无法工作。
      • bashplotlib 上的hist 工具似乎是直方图创建器,而不是条形图绘图仪。
      猜你喜欢
      • 2020-11-10
      • 2019-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-31
      • 2022-11-23
      • 1970-01-01
      相关资源
      最近更新 更多