0
votes

I have data I would like to plot in a histogram style with a "cumulated" curve on top. I have the following problem:

My data consists of one column with the categories ("discharge") and one column with the quantity of values ("probability") that belong to the respective category. The last value of the category-column is ">100" summarizing all power plants that have a bigger discharge than the last numeric value ("100 m^3/s"). I have not found a solution to plot this last category and the respective values with the command plot 'datafile.dat' using 1:2 with boxes ... because (as I assume) in this case only numerical values are read out for the x-ticlabels, so the last category is missing. If

I plot it with this command plot 'datafile.dat' using 2:xtics(1) with boxes ... I get the last category ">100" plotted just fine.

BUT: if I use the latter command the x-axis labels appear in the normal font size. Even though I have the line set format x '\footnotesize \%10.0f' in my code.

I have read about explicit labels in the plotcommand line that overwrite format style which was set before but was not able to adapt it to my code. Changing ytic font size in gnuplot epslatex (multiplot)

Do you have an idea how to do this?

Excel screenshot to visualize what I want to achieve

Excel screenshot to visualize what I want to achieve

'datafile.dat'
discharge probability cumulated
10 20 20% 
20 10 10%
30 5 5%
40 6 6%
50 4 4%
60 12 12%
70 8 8%
80 15 15%
90 20 20%
100 6 6%
>100 4 4%`

[terminal=epslatex,terminaloptions={size 15cm, 8cm font ",10"}]
set xrange [*:*]
set yrange [0:20]
set y2range [0:100]
set xlabel 'Discharge$' offset 0,-1
set ylabel 'No. of power plants' offset 10.5
set y2label 'Cumulated probability' offset -10
set format xy '$\%g$'
set format x '\footnotesize \%10.0f'
set format y '\footnotesize \%10.0f'
set format y2 '\footnotesize \%10.0f'
set xtics rotate by 45 center offset 0,-1
set style fill pattern border -1
set boxwidth 0.3 relative
set style line 1 lt 1 lc rgb 'black' lw 2 pt 6 ps 1 dt 2
plot 'datafile.dat' using 1:2 with boxes axes x1y1 fs pattern 6 lc black notitle, \
'datafile.dat' using 1:3 with linespoints axes x1y2 ls 1 notitle
1
It seems like the linked plot is exactly what you want -- you have a "and bigger" category, and the cumulative curve goes all the way up to 100%. Is that what your code gives you, or is that what you would like to achieve? If it's the latter, then please post you data file and the gnuplot script that you have created so far. - user8153
I am sorry - it took me some while to get used to the coding (I know I should have tried to find out about that in the first place...my apologies). I updated the original question: I hope it is clearer now... - Sebastian Roe

1 Answers

1
votes

I am confused by your datafile; the numbers in the third column do not seem to be cumulative, and do not add up to 100%. Here is a solution that uses only the first two columns of your file:

set term epslatex standalone header "\\usepackage[T1]{fontenc}"
set output 'test.tex'

stats "datafile.dat" using 2
total = STATS_sum

set xlabel "Discharge" offset 0, 1.5
set xtics rotate

set ylabel "No. of power plants"
set ytics nomirror
set yrange [0:*]

set y2label "Cumulative probability"
set y2tics
set y2range [0:]

set boxwidth 0.3 relative
set style line 1 lt 1 lc rgb 'black' lw 2 pt 6 ps 1 dt 2

plot \
'datafile.dat' using 2:xtic("\\footnotesize " . stringcolumn(1)) with boxes axes x1y1 fs pattern 6 lc black notitle, \
'datafile.dat' using ($2/total) smooth cumulative with linespoints axes x1y2 ls 1 notitle

set output

enter image description here The trick is to add the latex command \footnotesize in front of each label in the using command. It also first computes the total number of power plants so that it can compute probabilities, and computes cumulative values with the smooth cumulative option.