Chart-GGPlot

 view release on metacpan or  search on metacpan

examples/scale_continuous_02_01.pl  view on Meta::CPAN

#!/usr/bin/env perl

use 5.016;
use warnings;

use Getopt::Long;
use Chart::GGPlot qw(:all);
use Chart::GGPlot::Util::Scales qw(percent);
use PDL::Core qw(pdl);
use PDL::Primitive qw(random);
use Data::Frame;

srand(0);

my $save_as;
GetOptions( 'o=s' => \$save_as );

my $df = Data::Frame->new(
    columns => [
        x => random(10) * 100000,
        y => pdl( [ 0 .. 9 ] ) / 9
    ]
);

my $p = ggplot(
    data    => $df,
    mapping => aes( x => 'x', y => 'y' )
)->geom_point()
  ->scale_y_continuous( labels => \&percent );

if ( defined $save_as ) {
    $p->save($save_as);
}
else {
    $p->show();
}

lib/Chart/GGPlot/Util/Scales.pm  view on Meta::CPAN


our @EXPORT_OK = qw(
  censor discard expand_range zero_range
  rescale squish
  hue_pal brewer_pal gradient_n_pal rescale_pal viridis_pal
  seq_gradient_pal div_gradient_pal
  area_pal
  identity_pal
  extended_breaks regular_minor_breaks log_breaks
  pretty pretty_breaks
  number comma percent dollar
  rgb255_to_csshex rgb_to_csshex
  csshex_to_rgb255
  colorname_to_csshex
);
our %EXPORT_TAGS = ( all => \@EXPORT_OK );


fun censor ( $p, $range = pdl([ 0, 1 ]), $only_finite = true ) {
    my ( $min, $max ) = $range->minmax;
    my $finite = $only_finite ? $p->isfinite : PDL->ones( $p->length );

lib/Chart/GGPlot/Util/Scales.pm  view on Meta::CPAN

    return false if ($p->abs->max > $threshold);
    return !(
        (
            $p->badflag
            ? ( ( $p->floor == $p ) | $p->isbad )
            : ( $p->floor == $p )
        )->all
    );
}

fun percent ($p, :$accuracy=undef, :$scale=100,
             :$prefix='', :$suffix="%",
             :$big_mark=',', :$decimal_mark='.'
        ) {
    return number(
        $p,
        accuracy => $accuracy,
        scale    => $scale,
        prefix   => $prefix,
        suffix   => $suffix
    );

t/06-util_scales.t  view on Meta::CPAN


subtest format => sub {
    no warnings 'qw';

    pdl_is( number( pdl( 1000, 2000 )),
        PDL::SV->new( ['1 000', '2 000'] ), "number()" );

    pdl_is( comma( pdl( 1000, 2000 )),
        PDL::SV->new( [qw(1,000 2,000)] ), "comma()" );

    pdl_is( percent( pdl( 0 .. 5 ) / 5 ),
        PDL::SV->new( [qw(0% 20% 40% 60% 80% 100%)] ), "percent()" );

    pdl_is( dollar( pdl( 0, 1 )),
        PDL::SV->new( [qw($0 $1)] ), "dollar()" );
    pdl_is( dollar( pdl( 1000, 2000 )),
        PDL::SV->new( [qw($1,000 $2,000)] ), "dollar()" );
    pdl_is( dollar( pdl( 0, 1.01, -2.1), negative_parens => true),
        PDL::SV->new( [qw($0.00 $1.01 ($2.10))] ), "dollar()" );
};

# Util::_Labeling



( run in 0.358 second using v1.01-cache-2.11-cpan-624ce96ca49 )