setting the range of an histogram and plotting it to file
Subject: setting the range of an histogram and plotting it to file
From: Jaime Villate
Date: Sun, 05 Apr 2009 12:52:44 +0100
On S?b, 2009-04-04 at 10:24 +0200, Antonio Ragagnin wrote:
> Hi, i'm trying to do an histogram using the package descriptive.
> i use it in a batch script so i cannot see it (i think it is closed
> when the script finish)
If you include in the batch file:
set_plot_option([plot_format,gnuplot]),
two files will be created in your home directory: maxout.gnuplot and
data.gnuplot
You can run gnuplot and load the file maxout.gnuplot to see the
histogram.
> instead it have done a similar function:
>
> gist(lista, intervallo, min, max, n):=
> block(
> istogramma: makelist(0,i,1,n),
> gaussiana : makelist([0,0],i,1,n),
> for elem in lista do
> (
>
> cnt:1,
> while cnt <= n do
> (
> if elem>min+((cnt-1)*intervallo) then if
> elem<=min+((cnt)*intervallo) then
> istogramma[cnt] : istogramma[cnt]+1,
> cnt:cnt + 1
> )
>
> ), i:1,
> while i <= n do
> (
> gaussiana[i]:[min+((i-1)*intervallo),istogramma[i]],
> i:i+1
> ),
> gaussiana
> );
> it works, but i don't know how to plot it!!
I will show you how, but first, I would like to suggest a different
programming style for the same program you wrote:
gist (lista, intervallo, min, max, n):= block (
[istogramma: makelist(0, i, 1, n), gaussiana:[]],
for elem in lista do
(for cnt:1 thru n do
(if (elem > min + (cnt-1)*intervallo) then
if elem <= min + ((cnt)*intervallo) then
istogramma[cnt]: istogramma[cnt] + 1)),
for i:1 thru n do
gaussiana: endcons([min+(i-1)*intervallo,istogramma[i]],gaussiana),
gaussiana)$
In order to make the plot, we can change your program as this:
gist2 (lista, intervallo, min, max, n):= block (
[istogramma: makelist(0, i, 1, n), gaussiana:[]],
for elem in lista do
(for cnt:1 thru n do
(if elem > min + ((cnt-1)*intervallo then
if elem <= min + ((cnt)*intervallo) then
istogramma[cnt]: istogramma[cnt] + 1)),
for i:1 thru n do (
x1: min + (i-1)*intervallo,
x2: x1 + intervallo,
gaussiana: endcons (['discrete, [[x1, 0], [x1, istogramma[i]],
[x2, istogramma[i]], [x2, 0], [x1, 0]]], gaussiana)),
gaussiana)$
And now use can use it as this:
(%i21) gist2([0,3,5,7,7,11,11,11,11,15,15,15], 2, 0, 20, 10)$
(%i22) plot2d(%, [legend, false], [style, [lines,4,1]], [y,0,5]);
I hope this is useful.
Cheers,
Jaime