【问题标题】:How to plot an histogram and a constant line from different files如何绘制来自不同文件的直方图和恒定线
【发布时间】:2016-01-25 11:55:30
【问题描述】:

我是 gnuplot 的新手,遇到了一个问题:

我有 2 个不同的文本文件,第一个 (file1.txt) 是这样的:

Switch,Port,BPS
S1,1,5464091.33
S1,3,5465677.33
S2,2,5463298.00
S2,3,5462729.67
S3,1,5461340.67
S3,3,5461772.33

我用直方图绘制“file1.txt”:

plot avg_file using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader

这很好用。

现在我有 file2.txt,其中包含一个值:

AVG_BPS
4844714.81

我想将此值绘制为上一个图表(直方图)上的一条恒定水平线。

这是我的完整脚本:

# Terminal definition (PNG image)
set term png

# Settings
set datafile separator ","
set output 'myplot.png'
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 1

# Graph and Axis titles
set title  "BPS"
set xlabel "Switch-Port"
set ylabel "bits-per-second"

# Plot
plot "file1.txt" using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader

这里是myplot.png

谢谢

【问题讨论】:

    标签: plot gnuplot line histogram


    【解决方案1】:

    可能最好的方法是stats

    stats 'file2.txt' u 1
    hor_value=STATS_min
    

    然后添加到你的情节中:

    plot "file1.txt" using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader, hor_value 
    

    或者在顶部放置一条线(在最后一个图之前):

    set arrow nohead from graph 0, hor_value to graph 1, hor_value front
    

    【讨论】:

    • 谢谢,它适用于 STATS。只是一件小事:当我运行我的脚本时,它会在终端上打印一些统计信息,我该如何防止这种情况发生?
    • stats 有一个nooutput 标志。在 gnuplot 控制台中查看 help stats
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多