Hey everyone,

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!!!!


In reply to Plotting a Hash Key-value pair by krish28

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.