柱状图
--------------数据文件'requests.txt' 内容-------------------------------------------
### 文件开始 ###
# 每秒request性能比较 (mm)
#
Requests Trace_OFF Log4cpp_file old_Trace new_Trace
# ======================
on
2_module 3552 712 1166 2471
### 文件结束 ###
------------------------------------------------------------------------
命令
gnuplot> set style da
gnuplot> set style histogram clustered gap 1
gnuplot> set style fill solid 0.4 border
plot 'requests.txt' using 2:xticlabels(1) title columnheader(2), '' using 3:xticlabels(1) title columnheader(3), '' using 4:xticlabels(1) title columnheader(4),'' using 5:xticlabels(1) title columnheader(5)
参考了这里,这个博客例子不错
谈谈gnuplot(三十七):柱状图
http://blog.sciencenet.cn/blog-373392-527507.html
谈谈gnuplot(四十):统计直方图
http://blog.sciencenet.cn/blog-373392-529904.html
复制一下,便于查找
除了点线图外,柱状图也是一种常用的作图方式。我们还用前两讲用过的 "precipitation.dat“ 数据文件作例子:
gnuplot> set style da
gnuplot> set style histogram clustered gap 1
gnuplot> set style fill solid 0.4 border
gnuplot> plot "precipitation.dat" using 2, '' using 3

这里我们发现一个 histogram 和一般点线作图的不同:一般点线作图,每个图都要提供 x,y 两组数据,而 histogram 图只需要提供一组数据,每个数据自动画在 X 轴上的非负整数位置。这时候,X 轴上的标注并不是我们想要的,图例中的标注也不符合我们的要求。我们以前在“ 坐标取值范围及刻度 ”和“ 多组数据绘图 ”讲过,这两处的标注,可以分别用 set xtics 命令和 title 参数来设置。这里提供另一种改变标注的方法,我们把 " precipitation.dat “ 文件稍微修改一下:
### 文件开始 ###
# 各城市月平均降水量 (mm)
#
月份 北京 上海
# ======================
一月 2.5 38.1
二月 5.1 58.4
三月 10.2 81.3
四月 25.4 101.6
五月 27.9 114.3
六月 71.1 152.4
七月 175.3 129.5
八月 182.9 132.1
九月 48.3 154.9
十月 17.8 61.0
十一月 5.1 50.8
十二月 2.5 35.6
### 文件结束 ###
我们把修改后的文件称作 " precipitation_v2.dat "。和原文件相比,这里有两处改动:
-
原文件中包含城市名称的一行是注释掉的,新文件里这一行表示注释的 # 字符被去掉了;
-
原文件中第一列用阿拉伯数字表示的月份,新文件里被换作了中文月份名称。
gnuplot> plot "precipitation_v2.dat" using 2:xticlabels(1) title columnheader(2), '' using 3:xticlabels(1) title columnheader(3)

除了 clustered 模式, histogram 作图还有 rowstacked 模式,就是把几组数据竖着垒起来:
gnuplot> set style histogram rowstacked
gnuplot> set boxwidth 0.8 relative
gnuplot> set xtics rotate by -45
gnuplot> replot

既然有 rowstacked ,有没有 columnstacked 呢?答案是有的。 rowstacked 逐行把数据叠加显示,而 columnstacked 逐列把数据叠加。除此之外,还有 errorbars 模式,在 clustered 基础上增加 误差条。由于这两种模式和之前讲过的很类似,所以就不举例了。

1165

被折叠的 条评论
为什么被折叠?



