Search code examples
labelgnuplot

Gnuplot using xtic from data but plotting only every 10th


I have a pretty dense data set along the x-axis and plot it using with boxes as histogram. My data table has entries for x axis labels. The x labels are becoming too dense. How do I let's say print only every 10th of them.

plot 'histo.raw' using 3:xtic(2) with boxes lc rgb 'orange'  title 'data'

Sample data:

130 " +0.145 ->  +0.150"      0   0.00
131 " +0.150 ->  +0.155"      0   0.00
132 " +0.155 ->  +0.160"      0   0.00
133 " +0.160 ->  +0.165"      1   0.00
134 " +0.165 ->  +0.170"      2   0.00
135 " +0.170 ->  +0.175"      2   0.00
136 " +0.175 ->  +0.180"      4   0.00
137 " +0.180 ->  +0.185"      9   0.01
138 " +0.185 ->  +0.190"     31   0.03
139 " +0.190 ->  +0.195"     74   0.07
140 " +0.195 ->  +0.200"    114   0.11
141 " +0.200 ->  +0.205"    126   0.13
142 " +0.205 ->  +0.210"    114   0.11
143 " +0.210 ->  +0.215"    120   0.12
144 " +0.215 ->  +0.220"    181   0.18
145 " +0.220 ->  +0.225"    216   0.22
146 " +0.225 ->  +0.230"    367   0.37
147 " +0.230 ->  +0.235"    503   0.50
148 " +0.235 ->  +0.240"    648   0.65
149 " +0.240 ->  +0.245"    788   0.79
150 " +0.245 ->  +0.250"    960   0.96

If I do i.e.

set xtics 0,10 in rotate by 90 offset first +0.5,0 right
plot 'histo.raw' using 3 with boxes lc rgb 'orange'  title 'data'

I get the desired spaced out labels. But my label text from the data file is gone and just replaced by line count (which I don't want)

Thanks for your feedback.


Solution

  • You can replace the using 3:xtic(2) with an expression that produces a label only if the row number $0 is divisible by 10:

    plot 'histo.raw' \
     using 3:xtic((int($0) % 10)==0?stringcolumn(2):"") \
     with boxes lc rgb 'orange'  title 'data'
    

    enter image description here