3
# Demo x13 for the PLplot PDL binding
5
# Does a simple pie chart
7
# Copyright (C) 2004 Rafael Laboissiere
9
# This file is part of PLplot.
11
# PLplot is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU Library General Public License as published
13
# by the Free Software Foundation; either version 2 of the License, or
14
# (at your option) any later version.
16
# PLplot is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU Library General Public License for more details.
21
# You should have received a copy of the GNU Library General Public License
22
# along with PLplot; if not, write to the Free Software
23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27
# N.N. Although the visual results of this script is essentially the
28
# same as that produced by the equivalent C example x13c, the code
29
# below is quite different from that of x13c.c. I use the vectorized
30
# operations of PDL extensively, such that most of the "for" loops
34
use PDL::Graphics::PLplot;
35
use Math::Trig qw [pi];
45
my $per = pdl [10, 32, 12, 30, 16];
47
# Parse and process command line arguments
49
plParseOpts (\@ARGV, PL_PARSE_SKIP | PL_PARSE_NOPROGRAM);
56
# Ensure window has aspect ratio of one so circle is
57
# plotted as a circle.
59
plwind(0., 10., 0., 10.);
60
#plenv (0, 10, 0, 10, 1, -2);
62
# n.b. all theta quantities scaled by 2*pi/500 to be integers to avoid
63
# floating point logic problems.
66
for (my $i = 0; $i <= 4; $i++) {
67
# n.b. the theta quantities multiplied by 2*pi/500 afterward so
68
# in fact per is interpreted as a percentage.
69
my $theta1 = 5 * $per->index ($i);
70
my $theta = $theta0 + sequence ($theta1->sclr + 1) * $dthet;
71
my $xx = 5 + 3 * cos ((2 * pi / 500) * $theta);
72
my $n = ($xx->dims)[0];
73
my $x = zeroes ($n + 1);
74
$x->slice("1:$n") .= $xx;
76
my $yy = 5 + 3 * sin ((2 * pi / 500) * $theta);
77
my $y = zeroes ($n + 1);
78
$y->slice("1:$n") .= $yy;
81
plpsty (($i + 3) % 8 + 1);
85
my $just = (2 * pi / 500) * ($theta0 + $theta1 / 2);
86
my $dx = .25 * cos ($just);
87
my $dy = .25 * sin ($just);
88
$just = ((2 * $theta0 + $theta1) < 250
89
|| (2 * $theta0 + $theta1) > 750) ? 0 : 1;
90
plptex (($xx->index ($n / 2) + $dx), ($yy->index ($n / 2) + $dy),
91
1.0, 0.0, $just, $text[$i]);
96
plptex (5.0, 9.0, 1.0, 0.0, 0.5, "Percentage of Sales");