2

I am using Gnuplot to create a histogram with a plot line, however, the plot line is not fit well with bar head, also I would like to put the line a little bit far from the bar head.

enter image description here

set border 3 
set boxwidth 0.9
set tics nomirror out scale 0.75
set style fill solid 0.8

plot "03.txt" using 2:xtic(1) lt rgb "#0060ad" notitle, "" using 2 smooth csplines notitle with lines ls 1, "" using 3 lt rgb "#ff6600" notitle, "" using 3 smooth csplines notitle with lines ls 2, "" using 4 lt rgb "#dd181f" notitle, "" using 4 smooth csplines notitle with lines ls 3

Updated:

This is the data file:

500000      25.938          25.938      2
1000000     52.385          52.385      4
1500000     79.749          78.405      6.125
2000000     152.589         100.261     12.479
2500000     224.869         118.364     19.159
2
  • It's always better to post your datafile (or a significant part of it). I believe you'll achieve what you want with some tuning of the splines's using clause, but there could be some influence of the content of your column 2 on an easy choice. By "put the line a little bit far from the bar head", do you mean a vertical shift of the whole spline ? Commented Apr 12, 2017 at 18:02
  • @Joce I added the data file, yes, I need a vertical shift to avoid sticking the plot line with bars head. Commented Apr 13, 2017 at 2:57

1 Answer 1

2

This should work for any number of columns, you have to specify them in the variable N, and number them in calls to custom function xbox. This should do for a non-intensive usage. You can offset vertically the curves with the OFFSET variable (in units of y axis)

set border 3
#number of columns to be plotted
N=3
#vertical offset
OFFSET=0
#gapwidth (set to gnuplot's default)
GW=2
xbox(x,i)=x+(i-N*0.5)/(N+GW)
set boxwidth 0.9
set tics nomirror out scale 0.75
set style fill solid 0.8

plot "03.txt" using 2:xtic(1) lt rgb "0060ad" notitle,  \
         "" using 2 with histogram notitle,     \
         "" using (xbox($0,1)):($2+OFFSET) smooth csplines notitle with lines ls 1,     \
         "" using 3 lt rgb "#ff6600" notitle with histogram,    \
         "" using (xbox($0,2)):($3+OFFSET) smooth csplines notitle with lines ls 2,     \
         "" using 4 lt rgb "#dd181f" notitle with histogram,    \
         "" using (xbox($0,3)):($4+OFFSET) smooth csplines notitle with lines ls 3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.