krish28 has asked for the wisdom of the Perl Monks concerning the following question:
I need some help with plotting a histogram of a hash's keys vs their values. In my code, i have a hash whose Keys (>60,700 at last count) are numbers and the Values for these is the number of times the Key appears in the file that i am reading
With this data, i want to plot the Keys in the X" and their Values in the Y", preferably like a Histogram. Currently i just use the GD::Graph::Histogram module, which tries to plot JUST my hash's Keys vs their counts(hash's values not used). But its not working successfully and i keep getting the error "Horizontal size too small, vertical size too small" etc if i try changing the parameters. Here is what i have in my code
$bins = int(($keys[$#keys]-$keys[1])/$histowindowsize); ###histowindowsize is some integer (i have tried 1000 and got errors) my $graph = new GD::Graph::histogram(800,600); $graph -> set( x_label => 'Hash's Keys', y_label => 'count of keys in file', title => 'Key count histogram', histogram_bins => $bins, x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 1, shadowclr => 'dred', transparent => 0, ) or warn $graph -> error; my $gd = $graph -> plot (\@keys) or die $graph->error; open (IMG, '>histo.png') or die $!; binmode IMG; print IMG $gd -> png;
Should i try a different module instead or change my methodology? I want a Histogram image file as the output, but i am at my wit's end on how to get it. I'd appreciate any help..... Thanks in advance!!!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Plotting a Hash Key-value pair
by Khen1950fx (Canon) on Sep 28, 2010 at 05:07 UTC | |
|
Re: Plotting a Hash Key-value pair
by martin (Friar) on Sep 28, 2010 at 05:13 UTC | |
by moritz (Cardinal) on Sep 28, 2010 at 09:00 UTC | |
by krish28 (Acolyte) on Sep 28, 2010 at 22:38 UTC | |
by krish28 (Acolyte) on Sep 30, 2010 at 02:47 UTC | |
by roboticus (Chancellor) on Sep 30, 2010 at 03:40 UTC |