绘制横跨直方图条的水平线 [英] Plotting horizontal lines across histogram bars

查看:960
本文介绍了绘制横跨直方图条的水平线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实验,我测量一些算法相对于三个基线的性能。因此,我想为算法绘制直方图,通过直方图条绘制的各种样式的水平线来显示基线。

I have an experiment where I measured the performance of some algorithms relative to three baselines. I'd therefore like to plot histograms for the algorithms, with horizontal lines of various styles drawn through the histogram bars to show the baselines.

下面是我生成的示例通过在Gnuplot生成的图表上手动绘制水平线。直方图句子和文档表示我测试的算法,mono,random和MFS是基线。

Below is an example which I produced by manually drawing horizontal lines on a graph produced by Gnuplot. The histograms "sentence" and "document" represent the algorithms I tested, and "mono", "random", and "MFS" are the baselines.

我可以在Gnuplot本身做这个吗?如果没有,任何人都可以推荐另一个工具,可以做到这一点?或者,我应该使用更好的可视化技术?

Is there some way I can do this within Gnuplot itself? If not, can anyone recommend another tool which can do this? Or perhaps there's a better visualization technique I should be using instead?

推荐答案

这里有一个我做了一个例子:

This is definitely possible. Here's a little example that I cooked up:

首先,datafile data.dat

First, the datafile "data.dat":

#histograms
1 3 stack1
2 2 stack2
3 1 stack3


#mono
 .6
 .6

 1.5
 1.5

 3.1
 3.1

现在用gnuplot脚本绘制:

Now the gnuplot script to plot it:

set yrange [0:*]
set style data histograms 
set style histogram cluster gap 1

IDX=-1
xpos(x)=(IDX=IDX+1, IDX%2==0)?(IDX/2-.5):(IDX/2+.5)

set style fill solid
plot 'data.dat' index "histograms" u 1:xtic(3) title "column1", \
     '' index "histograms" u 2 title "column2", \
     '' index "mono" u (xpos($1)):1 w lines ls -1 title "mono"

这比我上一个版本有点棘手。当绘制直方图集群时,每个集群都以从0开始的整数为中心,并为每个集群增加1(不考虑xtics和labels的设置)。我所做的是使用这些信息来简化数据文件。现在这个plot命令绘制2个不同的数据集作为直方图(从数据文件的直方图部分中的每个列取得),第一个添加xtic标签。然后棘手的部分:我写一个有副作用的函数(gnuplot内联函数是新的在gnuplot 4.4我想)。每次调用时,变量 IDX 的值递增 - 因此,xrange上的当前位置总是 IDX / 2 。此函数在返回 IDX / 2-.5 IDX / 2 + .5 之间交替。注意,要创建另一个数据集 random ,您将需要另一个函数 xpos2 ,它与 xpos1 ,除非它使用单独的迭代器。

This is a little more tricky than my last version. When plotting a cluster of histograms, each cluster is centered on an integer starting at 0 and incrementing by 1 for each cluster (regardless of your setting for xtics and labels). What I've done is used that information to simplify the datafile. Now this plot command plots 2 different data sets as histograms (taken from each column in the "histogram" portion of the datafile), the first one adds the xtic labels. Then the tricky part: I write a function which has side-effects (gnuplot inline-functions are new in gnuplot 4.4 I think). Each time it is called, the value for the variable IDX is incremented -- So, the current position on the xrange is always IDX/2. This function alternates between returning IDX/2-.5 and IDX/2+.5. Note that to create another dataset random, you'll need another function xpos2 which is the same as xpos1 except it uses a separate iterator.

这篇关于绘制横跨直方图条的水平线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆