1

I have a file contains wire length ranging from 300-1000. How do I use GNUPLOT to make a histogram with length on X-axis (With interval of 100) and number of wires on Y-axis?

For example:

250 wire_0
350 wire_1
360 wire_2
800 wire_3

I want a bar with height of 1 representing wire_0, a bar with height of 2 representing wire_1 and wire_2 and a bar with height of 1 representing wire_3.

B--rian
  • 5,578
  • 10
  • 38
  • 89
Bryan
  • 309
  • 1
  • 8
  • 16

1 Answers1

1

Edit #1

Based on both this and this answers, your could try:

binwidth = 100
bin(x, width) = width*floor(x/width)

set tics out nomirror
set style fill transparent solid 0.5 border lt -1
set xrange [0:1000]
set xtics binwidth
set boxwidth binwidth
set yrange [0:3]

$data <<EOD
250 wire_0
350 wire_1
360 wire_2
800 wire_3
EOD

plot $data u (bin($1,binwidth)):(1.0) smooth freq with boxes notitle

Result

result

Edit #2

If you need the of values above the boxes, you can use.

set table $data2
    plot $data u (bin($1,binwidth)):(1.0) smooth freq with boxes;
unset table

plot $data2 u 1:2 w boxes notitle , "" u 1:2:2 w labels offset 0,1 notitle

Result result 2

grsousajunior
  • 743
  • 1
  • 6
  • 12
  • Thank you, but I really want to plot length on X-axis and count on Y-axis, that way wire_1 and wire_2 will be merged into 1 bar with height of 2 (300~400). – Bryan Sep 05 '19 at 17:34
  • Thank you so much, I changed "yrange [0:3]" to "yrange[0:*]" and it works beautifully. BTW, if I want to put a text ontop of each bar to show the height how do I do that? – Bryan Sep 10 '19 at 23:31