2012-03-22 47 views
3

我想在gnuplot中将两个数据系列绘制在一个图中作为框。目前的脚本如下所示:“gnuplot”旁边有两个“盒子”相邻的地块

set terminal postscript eps enhanced color 
set title "Distribution of the extrepreneur PnL. Loan $6." 
set output 'pnl_loan6.eps' 


#set xrange [0:] 
set xlabel "Discounted profit" 

set style fill solid 0.8 border -1 
plot 'pnl_loan6.txt' using 1:2 title 'PnL high risk (xi=1)' with boxes,\ 
    'pnl_loan6.txt' using 1:3 title 'PnL high risk (xi=1.5)' with boxes 

但是这两个系列重叠。除了重叠之外,我希望有一个系列在现有盒子的左半边画一个盒子,另一个在右半边,以便它们有效地交替。我该怎么做?

编辑:

  1. 我尝试了直方图,但是这并没有看起来非常好。 xtics不是我之后的东西,而且列之间有空格。
  2. 样品的数据(第20列满分100分):

数据:

-10.000000 20251.000000 31825.000000 
-4.892638 26743.000000 21310.000000 
0.214725 20362.000000 14590.000000 
5.322087 13023.000000 9645.000000 
10.429449 7730.000000 6347.000000 
15.536812 4636.000000 4331.000000 
20.644174 2714.000000 2964.000000 
25.751536 1647.000000 2121.000000 
30.858899 1044.000000 1586.000000 
35.966261 648.000000 1106.000000 
41.073624 396.000000 873.000000 
46.180986 257.000000 685.000000 
51.288348 166.000000 471.000000 
56.395711 101.000000 369.000000 
61.503073 83.000000 321.000000 
66.610435 52.000000 260.000000 
71.717798 40.000000 184.000000 
76.825160 30.000000 172.000000 
81.932522 21.000000 143.000000 
87.039885 11.000000 116.000000 
+0

你绘制什么样的数据? (是数据文件顺序整数的第一个字段中的内容?如果我有一个小数据文件可以使用,我可能会给你一个更完整和经过测试的答案) – mgilson 2012-03-22 18:27:23

+0

@mgilson,请参阅编辑。 – Grzenio 2012-03-23 07:26:52

回答

9

我真的不知道你是什么之后,但也许这一点hackerish方法将这样的伎俩:

set style fill solid 0.8 border -1 
set boxwidth 0.5 relative 
plot 'pnl_loan6.txt' using ($1+1.27684075):2 title 'PnL high risk (xi=1)' with boxes,\ 
    'pnl_loan6.txt' using ($1-1.27684075):3 title 'PnL high risk (xi=1.5)' with boxes 

到脚本不同的是

  1. 设置boxwidth做0.5的相对
  2. 将坐标图在x轴上偏移一半距离(这仅适用于您的x轴缩放等距离的情况。

总之,这是导致情节:

enter image description here

PS: 你可能要考虑在y轴的对数标度与set logscale y这将导致该地块:

enter image description here

+0

这正是我所追求的!常数“+ -1.27684075”来自哪里?如果数据发生变化,他们可能会改变吗? – Grzenio 2012-03-23 10:35:28

+0

常量来自您的数据。你的数据以delta x = 5.1间隔 - 所以每个盒子的宽度是该距离的一半(约2.55)。上面的脚本将第一个盒子向左移动一个盒子宽度(-1.27),第二个盒子向右移动一个盒子宽度(1.27)。所以,如果x数据的间距发生变化,这些常量将会改变数值。 – mgilson 2012-03-23 15:46:22

+0

可以使用'stats'命令(我喜欢它)自动提取这些信息:'stats'file.txt'using every every :::: 1 nooutput; ofs = 0.25 *(STATS_max-STATS_min);剧情......使用($ 1)...'。 – Christoph 2013-09-12 13:33:30

0

你可以尝试histogram风格...也许set boxwidth

编辑

对于boxwidth看到Woltan的答案 - 看到你的数据文件后,这可能是最好的办法。

你可以这样做:

set style histogram cluster gap 0 
plot "datafile.dat" u 2:xtic(1) with histogram ... 

但是,你有一个多拥挤的x轴在这种情况下 - 但要标注与弦轴的情况下,这种方法的伟大工程。

最后一点: 这可能是一个好主意,这样做以下 -

set style fill solid 0.8 border -1 
set boxwidth 0.5 relative 
plot 'datafile.dat' using ($1+1.27684075):2 title 'PnL high risk (xi=1)' with boxes,\ 
    '' using ($1-1.27684075):3 title 'PnL high risk (xi=1.5)' with boxes lc rgb "#0000ff" 

这改变的绿框为蓝色(#0000FF)的颜色,因为人〜5%是红色/绿色色盲。 (你可以使用“蓝色”而不是“#0000ff” - 但后者更一般)。

+0

嗨,我尝试了直方图风格,但它似乎做了一个不同的事情。你能给出一个这个设置boxwidth的例子吗?我如何指定我想要一半的原件?另外我需要将一个移动到左边,另一个移动到右边? – Grzenio 2012-03-23 07:20:56