Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Histogram Creation

by toolic (Bishop)
on Jul 18, 2018 at 16:03 UTC ( [id://1218765]=note: print w/replies, xml ) Need Help??


in reply to Histogram Creation

I can't reproduce your output, but here is a simplified version of your code that creates an output PNG file for me (if I input some simple numbers in a file):
use strict; use warnings; use GD::Graph::histogram; my $input = 'distance.txt'; unless(open(INPUT, $input)) { die "\nCannot open input\n"; } my @data; while(my $line = <INPUT>) { chomp $line; push @data, sprintf ("%.1f\n", $line); } my $graph = new GD::Graph::histogram(400,600); $graph->set( y_label => 'Count', x_label => 'Distances', title => 'Histogram', x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 1, shadowclr => 'dred', transparent => 0, ) or warn $graph->error; my $image = $graph->plot(\@data) or die $graph->error; open( IMG, '>' . 'out.png' ) or die $!; binmode IMG; print IMG $image->png;

Post a few lines of your input file (inside "code" tags).

Your $filename variable is undefined because you didn't pass any arguments to your "main" sub. @_ holds args passed to a sub. Also, you keep clobbering your @data when you assign it to @_ (which is empty).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1218765]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-28 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found