Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Way to limit xtics in histogram

3,465 views
Skip to first unread message

Juho Jokelainen

unread,
Jan 20, 2010, 6:59:52 AM1/20/10
to
Gnuplot does not automaticly limit the amount of xticlabels in
histograms like it does with other plotting types.
To illustrate the problem:
http://shiona.ath.cx/count.png
I guess there are 61 xtics, maybe one of five could be ok.
Any help appreciated.

(Because some of you might possibly request the script, here it is:

set boxwidth 0.75 absolute
set style fill solid 1.00 border -1
set style data histogram
set style histogram cluster gap 1
set xtics nomirror out rotate by -30;

set title "Daily number of packages received from node \n \
during 18.11.2009 - 18.1.2009"

plot "ready/count" using 2:xtic(1) t '1978', \
"ready/count" using 3 t '2473'

)

sfeam

unread,
Jan 20, 2010, 3:23:27 PM1/20/10
to
Juho Jokelainen wrote:

> Gnuplot does not automaticly limit the amount of xticlabels in
> histograms like it does with other plotting types.
> To illustrate the problem:
> http://shiona.ath.cx/count.png
> I guess there are 61 xtics, maybe one of five could be ok.
> Any help appreciated.

The form xtic(1) is shorthand for xtic(stringcolumn(1)).
That is, xtic(foo) really expects a function foo that returns a string.

The command xtic(1) is doing exactly what you asked, which is to
place an tic label for every entry in column 1. So you need to do
something slightly different. The basic idea should be evident
from this command:

everyfifth(col) = (int(column(col) % 5 == 0) ? "A" : ""
plot 'data' using 1:2:(everyfifth(0))

The function everyfifth(0) returns a string value for each point
in the data set. Column 0 by convention holds the index of that
point within the data set. The string is set to "A" for every
5th point, and "" otherwise.

But you don't want "A". You want the contents of column 1,
treated as a string. So we change this to

everyfifth(col) = (int(column(col)) % 5 == 0) ? stringcolumn(1) : "")


Ethan

Juho Jokelainen

unread,
Jan 20, 2010, 8:42:04 PM1/20/10
to

> The command xtic(1) is doing exactly what you asked, which is to
> place an tic label for every entry in column 1. So you need to do
> something slightly different.  The basic idea should be evident
> from this command:
>
>   everyfifth(col) = (int(column(col) % 5 == 0) ? "A" : ""
>   plot 'data' using 1:2:(everyfifth(0))
>
Thanks.
I was thinking that I'd propably need some kind of if-block there but
didn't know the syntax.
I also thought that there is "set xtics start, frequency" but that
doesn't seem to work for strings.
But yeah, this should get my work done, thanks again.

噜噜老公

unread,
Mar 8, 2010, 2:05:59 AM3/8/10
to


Hi,
I have incorprated this solution into my gnuplot script. But it
failed to generate histogram graph.
Could someone help me? Thanks.

My Data file (hist.txt):

bin distibution
0.100000 0.000000
0.200000 0.003273
0.300000 0.000818
0.400000 0.000818
0.500000 0.001637
0.600000 0.004092
0.700000 0.000818
0.800000 0.001637
0.900000 0.000818
1.000000 0.001637
1.100000 0.000000
1.200000 0.000000
1.300000 0.001637
1.400000 0.000818
1.500000 0.000818
1.600000 0.000818
1.700000 0.001637
1.800000 0.000000
1.900000 0.000000
2.000000 0.004910
2.100000 0.007365

My Gnuplot Script (bin_hist_gp.txt):
set xlabel "Bin Size "
set ylabel "Density "
unset key
set size 1.0, 1.0
set origin 0.0, 0.0


set style data histogram
set style histogram cluster gap 1

set style fill solid border -1
set boxwidth 0.75
set t png size 400,300
everytenth(col) = (int(column(col))%10 ==0)?stringcolumn(1):""
plot "hist.txt" u 2:(everytenth(0)) title "Distribution"
set output
exit

And the final output message after it is executed in gnuplot.
"
gnuplot bin_hist_gp.txt

plot "hist.txt" u 2:(everytenth(0)) title "Distribution"
^
"bin_hist_gp.txt", line 12: Too many columns in using specification

"

And when I replace the code 'plot "hist.txt" u 2:(everytenth(0)) title
"Distribution" ' as ' plot "hist.txt" u 2:xticlabels(everytenth(0))
title "Distribution" '. It failed with unrecognized message. I
have no idea about the real issue.

dir...@googlemail.com

unread,
Sep 26, 2012, 4:28:01 AM9/26/12
to
Because this thread is nearly the only one I found while searching the web I will post my improved solution of every... here:

everyNth(countColumn,labelColumnNum,N) =((int(column(countColumn)) % N == 0) ? stringcolumn(labelColumnNum) : "");

and you have to use it this way:

plot ... u 1:xtic(everyNth($2,2,10))

tommy.ca...@gmail.com

unread,
Jan 23, 2014, 7:35:52 PM1/23/14
to
Is it possible that there is a syntax error in the code you have provided?

Karl

unread,
Jan 24, 2014, 8:48:47 AM1/24/14
to
Am 24.01.2014 01:35, schrieb tommy.ca...@gmail.com:
> Is it possible that there is a syntax error in the code you have provided?
>

This is a newsgroup, dude, you have to quote the old posting.

I should sue google for stealing my old newspost and pretending i took
part in some "googlegroup". :-[

wax...@gmail.com

unread,
Jun 16, 2014, 11:45:54 AM6/16/14
to
On Wednesday, September 26, 2012 4:28:01 AM UTC-4, dir...@googlemail.com wrote:
> Because this thread is nearly the only one I found while searching the web I will post my improved solution of every... here:

Here's a complete, stand-alone, runnable script:

#!/bin/sh

# Generate the input data file. Columns are:
# 1 datapoint identifier
# 2 Y value
# 3 xtic labels
perl -e 'for(500..600) {
printf "%d\t%.1f\t\"Foo %d\"\n",$_,rand($_)/10,$_
}
' >in.dat

gnuplot <<EOF
set term png size 1800, 1000
set xtics rotate by -90

nth(countCol,labelCol,n) = \
((int(column(countCol)) % n == 0) ? stringcolumn(labelCol) : "")

set output "out.png"
plot \
"in.dat" using 1:2:xtic(nth(1,3,10)) with linespoints \
pointtype 2 linecolor rgb "red"
EOF

display out.png &

Karl

unread,
Jun 16, 2014, 12:28:43 PM6/16/14
to
Am 16.06.2014 17:45, schrieb wax...@gmail.com:
> On Wednesday, September 26, 2012 4:28:01 AM UTC-4, dir...@googlemail.com wrote:
>> Because this thread is nearly the only one I found while searching the web I will post my improved solution of every... here:
>
> Here's a complete, stand-alone, runnable script:
>

It�d still be great if you gave everybody else here some context for
this. ;-)

People who use their newsreader instead of googlegroups don�t have the
previous posts directly at hand if they�re older than a few months or so.

K



0 new messages