Perl Histogram Area Plot example script from the perl graph gallery. Plotly makes free online charts with Perl and PDL and a GUI. Perl Histogram Area Plot | Example Code | plotly

Histogram Area Plot

Made with Perl graphing API

Back to the API Gallery

Perl Example Code


#!/usr/bin/perl

####################################
# Normal Distribution Histogram Demo 
# Questions? Email feedback@plot.ly
# For more docs, see plot.ly/api
####################################

use strict;
use warnings;

use constant PI => 4 * atan2(1, 1);

use WebService::Plotly;
use PDL;


my $plotly = WebService::Plotly->new( un => 'username', key => 'api_key' );


my $samples = grandom(50);

my $x_norm = unpdl(PDL->zeroes( 100 )->xlinvals( -5, 5 ));
my $y_norm = [ map { 1/sqrt(2*PI)*exp(-$_**2/2) } @$x_norm ];


my $l = {
	showlegend => 0,
	xaxis      => { zeroline => 0 },
	yaxis      => { zeroline => 0 },
};


my $response = $plotly->plot( 
	[
		{
			y        => $samples, 
			type     => 'histogramy',
			histnorm => 'probability density',
		}, 
       {
			x    => $x_norm, 
			y    => $y_norm, 
			fill => 'tozeroy',
		},
	],
	layout => $l,
);

print "url is:\n\t$response->{url}\n\n";
print "filename on our server is: \n\t$response->{filename}\n";