【问题标题】:Gnuplot set background color of data labelGnuplot 设置数据标签的背景颜色
【发布时间】:2016-03-15 19:48:25
【问题描述】:

我想将数据标签的背景设置为白色!考虑的图是以下数据(gnuDC.dat)的数据图:

4   1570.96 1571
8   770.63  771
12  530.33  530
16  385.13  385
24  261.87  262
48  137.71  138
96  81.42   81

绘图命令如下:

plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
 "gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
 "gnuDC.dat" using 1:3 notitle smooth csplines ls 14

这给了我:

看起来不错,但认为当它有白色背景时可以更好地阅读标签。有没有一种简单的方法可以一次为所有标签添加白色背景?

这是整个打印文件:

set terminal postscript eps size 14cm,10cm enhanced color \
        font 'Helvetica,18' linewidth 2

set output 'test.eps'

# Line style for axes
set style line 80 lt 0
set style line 80 lt rgb "#808080"

# Line style for grid
set style line 81 lt 3  # dashed
set style line 81 lt rgb "#808080" lw 0.5  # grey

set grid back linestyle 81
set border 3 back linestyle 80
set xtics nomirror
set ytics nomirror

set style line 100 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5
set style line 200 lc rgb '#a2142f' lt 1 lw 2 pt 7 ps 1.5
set pointintervalbox 0

set style line 1 lc rgb '#0072bd' lt 1 lw 1 pt 9 pi -10 ps 2
set style line 2 lc rgb '#77ac30' lt 1 lw 1 pt 7 pi -10 ps 2
set style line 3 lc rgb '#d95319' lt 1 lw 1 pt 1 pi -10 ps 2

set bmargin 4
set lmargin 5
set rmargin 4

unset title
set size 1,1
#set origin 0,0.27
set xlabel "number of cores, -"
set ylabel "Computational time, s"

set key top right
set key spacing 1.5
set key width -12

set yrange [0:1710]

plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
     "gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
     "gnuDC.dat" using 1:3 notitle smooth csplines ls 14

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    在 gnuplot 版本 5 中,有一个 boxed 选项可以做到这一点:给标签一个背景,如果你愿意的话,还有一个边框。样式由set style textbox 控制,例如

    set style textbox opaque noborder
    plot ... with labels boxed ...
    

    应用于您的脚本(由于自 5.0 起更改了破折号处理,因此进行了一些细微更改):

    # Line style for axes
    
    set style line 80 lt rgb "#808080"
    
    # Line style for grid
    set style line 81 dt 3  # dashed
    set style line 81 lt rgb "#808080" lw 0.5  # grey
    
    set grid back linestyle 81
    set border 3 back linestyle 80
    set tics nomirror
    
    set linetype 1 lc rgb '#0072bd' pt 9 pi -10 ps 2 dt 3
    
    set bmargin 4
    set lmargin 5
    set rmargin 4
    
    set xlabel "number of cores, -"
    set ylabel "Computational time, s"
    
    set key top right
    set key spacing 1.5
    set key width -12
    set yrange [0:1710]
    
    set style textbox opaque noborder
    
    plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p lt 1, \
         "gnuDC.dat" using 1:2:3 with labels boxed center offset 2.,0.7 font "Helvetica,10" tc ls 1 notitle, \
         "gnuDC.dat" using 1:3 notitle smooth csplines lt 1
    

    不,对于 4.6 及更早的版本,没有简单的方法来实现这一点。

    【讨论】:

    • 这正是我所需要的!一个问题:为什么你把线型改为线型……线型不再可用了吗?
    • 线型还是可以的,但我更喜欢线型
    • 你有什么喜欢它的原因,因为我总是对我的情节的外观有所改进:)
    • 在 gnuplot 5.0 版中,set style line 应该已被删除,但最终被保留了下来。如果我没记错的话,轮廓颜色等某些功能只能通过更改线型来正确处理,但不能通过线型来处理(也不能在使用设置样式增量用户时)。由于 gnuplot 5 允许自定义线型的所有方面(虚线类型、宽度、颜色、点类型、点大小),我自己认为不再需要使用线型。但请注意,该线型不受reset 的影响,但您必须使用reset session
    • 有道理!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 2017-05-29
    相关资源
    最近更新 更多