Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two plots "with boxes" next to each other with gnuplot

Tags:

gnuplot

I am trying to have two data series plotted in one graph as boxes in gnuplot. The script looks like this currently:

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

however the two series overlap. Instead of the overlap I would like to have one series draw its box in the left half of the existing box, and the other one in the right half, so that they effectively alternate. How can I do it?

EDIT:

  1. I tried a histogram plot, but this didn't look very good. The xtics were not what I was after and there were spaces in between the columns.
  2. Sample data (first 20 columns out of 100):

Data:

-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
like image 392
Grzenio Avatar asked Mar 22 '12 16:03

Grzenio


1 Answers

I am not really sure what you are after but maybe this little hackerish approach will do the trick:

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

The difference to your script is

  1. setting the boxwidth do 0.5 relative
  2. offsetting the plots by half the distance on the x-axis (this only works because your x-axis scaling is equidistant.

Anyhow this is the resulting plot:

enter image description here

PS: You might want to think about a logarithmic scaling on the y-axis with set logscale y which would result in this plot:

enter image description here

like image 92
Woltan Avatar answered Nov 15 '22 12:11

Woltan