-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplplot.pd
5303 lines (4273 loc) · 142 KB
/
plplot.pd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# User can set this global variable to 1 if he wants
# to use the normal plplot order of arguments, not the PP-required
# order for functions with OtherPars.
$PDL::Graphics::PLplot::standard_order = 0;
pp_addpm({At => Top}, <<'EOD');
use Carp qw(confess);
our $VERSION;
BEGIN {
$VERSION = '0.84';
};
=head1 NAME
PDL::Graphics::PLplot - Object-oriented interface from perl/PDL to the PLPLOT plotting library
=head1 SYNOPSIS
use PDL;
use PDL::Graphics::PLplot;
my $pl = PDL::Graphics::PLplot->new (DEV => "png", FILE => "test.png");
my $x = sequence(10);
my $y = $x**2;
$pl->xyplot($x, $y);
$pl->close;
Only version 5.15.0+ of PLplot is fully supported, due to a C-level API change
that is invisible at PDL-level. However, the library does support installation
with PLplot 5.13.0+.
For more information on PLplot, see
http://www.plplot.org/
Also see the test file, F<t/plplot.t> in this distribution for some working examples.
=head1 LONG NAMES
If you are annoyed by the long constructor call, consider installing the
L<aliased|aliased> CPAN package. Using C<aliased>, the above example
becomes
use PDL;
use aliased 'PDL::Graphics::PLplot';
my $pl = PLplot->new (DEV => "png", FILE => "test.png");
my $x = sequence(10);
# etc, as above
=head1 DESCRIPTION
This is the PDL interface to the PLplot graphics library. It provides
a familiar 'perlish' Object Oriented interface as well as access to
the low-level PLplot commands from the C-API.
=head1 OPTIONS
The following options are supported. Most options can be used
with any function. A few are only supported on the call to 'new'.
=head2 Options used upon creation of a PLplot object (with 'new'):
=head3 BACKGROUND
Set the color for index 0, the plot background
=head3 DEV
Set the output device type. To see a list of allowed types, try:
PDL::Graphics::PLplot->new();
=for example
PDL::Graphics::PLplot->new(DEV => 'png', FILE => 'test.png');
=head3 FILE
Set the output file or display. For file output devices, sets
the output file name. For graphical displays (like C<'xwin'>) sets
the name of the display, eg (C<'hostname.foobar.com:0'>)
=for example
PDL::Graphics::PLplot->new(DEV => 'png', FILE => 'test.png');
PDL::Graphics::PLplot->new(DEV => 'xwin', FILE => ':0');
=head3 OPTS
Set plotting options. See the PLplot documentation for the complete
listing of available options. The value of C<'OPTS'> must be a hash
reference, whose keys are the names of the options. For instance, to obtain
PostScript fonts with the ps output device, use:
=for example
PDL::Graphics::PLplot->new(DEV => 'ps', OPTS => {drvopt => 'text=1'});
=head3 MEM
This option is used in conjunction with C<< DEV => 'mem' >>. This option
takes as input a PDL image and allows one to 'decorate' it using PLplot.
The 'decorated' PDL image can then be written to an image file using,
for example, L<PDL::IO::Pic|PDL::IO::Pic>. This option may not be available if
plplot does not include the 'mem' driver.
=for example
# read in Earth image and draw an equator.
my $pl = PDL::Graphics::PLplot->new (MEM => $earth, DEV => 'mem');
my $x = pdl(-180, 180);
my $y = zeroes(2);
$pl->xyplot($x, $y,
BOX => [-180,180,-90,90],
VIEWPORT => [0.0, 1.0, 0.0, 1.0],
XBOX => '', YBOX => '',
PLOTTYPE => 'LINE');
$pl->close;
=head3 FRAMECOLOR
Set color index 1, the frame color
=head3 JUST
A flag used to specify equal scale on the axes. If this is
not specified, the default is to scale the axes to fit best on
the page.
=for example
PDL::Graphics::PLplot->new(DEV => 'png', FILE => 'test.png', JUST => 1);
=head3 ORIENTATION
The orientation of the plot:
0 -- 0 degrees (landscape mode)
1 -- 90 degrees (portrait mode)
2 -- 180 degrees (seascape mode)
3 -- 270 degrees (upside-down mode)
Intermediate values (0.2) are acceptable if you are feeling daring.
=for example
# portrait orientation
PDL::Graphics::PLplot->new(DEV => 'png', FILE => 'test.png', ORIENTATION => 1);
=head3 PAGESIZE
Set the size in pixels of the output page.
=for example
# PNG 500 by 600 pixels
PDL::Graphics::PLplot->new(DEV => 'png', FILE => 'test.png', PAGESIZE => [500,600]);
=head3 SUBPAGES
Set the number of sub pages in the plot, [$nx, $ny]
=for example
# PNG 300 by 600 pixels
# Two subpages stacked on top of one another.
PDL::Graphics::PLplot->new(DEV => 'png', FILE => 'test.png', PAGESIZE => [300,600],
SUBPAGES => [1,2]);
=head2 Options used after initialization (after 'new')
=head3 BOX
Set the plotting box in world coordinates. Used to explicitly
set the size of the plotting area.
=for example
my $pl = PDL::Graphics::PLplot->new(DEV => 'png', FILE => 'test.png');
$pl->xyplot ($x, $y, BOX => [0,100,0,200]);
=head3 CHARSIZE
Set the size of text in multiples of the default size.
C<< CHARSIZE => 1.5 >> gives characters 1.5 times the normal size.
=head3 COLOR
Set the current color for plotting and character drawing.
Colors are specified not as color indices but as RGB triples.
Some pre-defined triples are included:
BLACK GREEN WHEAT BLUE
RED AQUAMARINE GREY BLUEVIOLET
YELLOW PINK BROWN CYAN
TURQUOISE MAGENTA SALMON WHITE
ROYALBLUE DEEPSKYBLUE VIOLET STEELBLUE1
DEEPPINK MAGENTA DARKORCHID1 PALEVIOLETRED2
TURQUOISE1 LIGHTSEAGREEN SKYBLUE FORESTGREEN
CHARTREUSE3 GOLD2 SIENNA1 CORAL
HOTPINK LIGHTCORAL LIGHTPINK1 LIGHTGOLDENROD
=for example
# These two are equivalent:
$pl->xyplot ($x, $y, COLOR => 'YELLOW');
$pl->xyplot ($x, $y, COLOR => [0,255,0]);
=head3 CONTOURLABELS
Control of labels for contour plots.
Must either be 0 (turn off contour labels), 1 (turn on default contour labels)
or a five element array:
offset: Offset of label from contour line (if set to 0.0, labels are printed on the lines). Default value is 0.006.
size: Font height for contour labels (normalized). Default value is 0.3.
spacing: Spacing parameter for contour labels. Default value is 0.1.
lexp: If the contour numerical label is greater than 10^(lexp) or less than 10^(-lexp),
then the exponential format is used. Default value of lexp is 4.
sigdig: Number of significant digits. Default value is 2";
=for example
$pl->shadeplot ($z, $nsteps, BOX => [-1, 1, -1, 1], PLOTTYPE => 'CONTOUR', CONTOURLABELS => [0.004, 0.2, 0.2, 4, 2]);
$pl->shadeplot ($z, $nsteps, BOX => [-1, 1, -1, 1], PLOTTYPE => 'CONTOUR', CONTOURLABELS => 0); # turn off labels
$pl->shadeplot ($z, $nsteps, BOX => [-1, 1, -1, 1], PLOTTYPE => 'CONTOUR', CONTOURLABELS => 1); # use default labels
=head3 GRIDMAP
Set a user-defined grid map. This is an X and Y vector that
tells what are the world coordinates for each pixel in $z
It is used in 'shadeplot' for non-standard mappings between the
input 2D surface to plot and the world coordinates. For example
if your surface does not completely fill up the plotting window.
=for example
my $z = $surface; # 2D PDL to plot (generated elsewhere)
my $nlevels = 20;
my ($nx, $ny) = $z->dims;
my @zbounds = ($minx, $maxx, $miny, $maxy);
# Map X coords linearly to X range, Y coords linearly to Y range
my $xmap = ((sequence($nx)*(($zbounds[1] - $zbounds[0])/($nx - 1))) + $zbounds[0]);
my $ymap = ((sequence($ny)*(($zbounds[3] - $zbounds[2])/($ny - 1))) + $zbounds[2]);
$pl->shadeplot ($z, $nlevels, PALETTE => 'GREENRED', GRIDMAP => [$xmap, $ymap]);
=head3 GRIDMAP2
Set a user-defined two dimensional grid map. These are 2D X and Y matrices that
tell what are the world coordinates for each pixel in $z
It is used in 'shadeplot' for non-standard mappings between the
input 2D surface to plot and the world coordinates, for example
irregular grids like polar projections.
=for example
my $r_pts = 40;
my $theta_pts = 40;
my $pi = 4*atan2(1,1);
my $nlevels = 20;
my $r = ((sequence ($r_pts)) / ($r_pts - 1))->dummy (1, $theta_pts);
my $z = $r; # or any other 2D surface to plot...
my $theta = ((2 * $pi / ($theta_pts - 2)) * sequence ($theta_pts))->dummy (0, $r_pts);
my $xmap = $r * cos ($theta);
my $ymap = $r * sin ($theta);
$pl->shadeplot ($z, $nlevels, PLOTTYPE => 'CONTOUR',
JUST => 1,
BOX => [-1,1,-1,1],
PALETTE => 'GREENRED',
GRIDMAP2 => [$xmap, $ymap]);
=head3 LINEWIDTH
Set the line width for plotting. Values range from 1 to a device dependent maximum.
=head3 LINESTYLE
Set the line style for plotting. Pre-defined line styles use values 1 to 8, one being
a solid line, 2-8 being various dashed patterns.
=head3 MAJTICKSIZE
Set the length of major ticks as a fraction of the default setting.
One (default) means leave these ticks the normal size.
=head3 MINTICKSIZE
Set the length of minor ticks (and error bar terminals) as a fraction of the default setting.
One (default) means leave these ticks the normal size.
=head3 NXSUB
The number of minor tick marks between each major tick mark on the X axis.
Specify zero (default) to let PLplot compute this automatically.
=head3 NYSUB
The number of minor tick marks between each major tick mark on the Y axis.
Specify zero (default) to let PLplot compute this automatically.
=head3 PALETTE
Load pre-defined color map 1 color ranges. Currently, values include:
RAINBOW -- from Red to Violet through the spectrum
REVERSERAINBOW -- Violet through Red
GREYSCALE -- from black to white via grey.
REVERSEGREYSCALE -- from white to black via grey.
GREENRED -- from green to red
REDGREEN -- from red to green
=for example
# Plot x/y points with the z axis in color
$pl->xyplot ($x, $y, PALETTE => 'RAINBOW', PLOTTYPE => 'POINTS', COLORMAP => $z);
=head3 PLOTTYPE
Specify which type of XY or shade plot is desired:
LINE -- A line
POINTS -- A bunch of symbols
LINEPOINTS -- both
or, for 'shadeplot':
CONTOUR -- A contour plot of 2D data
SHADE -- A shade plot of 2D data
=head3 STACKED_BAR_COLORS
For 'bargraph', request a stacked bar chart.
Must contain a reference to a perl list of color names or RGB triples.
=for example
# $labels is a reference to a perl array with N x-axis labels
# $values is an NxM PDL where M is the number of stacked bars (in this case 2,
# since STACKED_BAR_COLORS contains two colors).
$pl->bargraph($labels, $values, STACKED_BAR_COLORS => ['GREEN', [128,0,55]);
=head3 SUBPAGE
Set which subpage to plot on. Subpages are numbered 1 to N.
A zero can be specified meaning 'advance to the next subpage' (just a call to
L<pladv()|/pladv>).
=for example
my $pl = PDL::Graphics::PLplot->new(DEV => 'png',
FILE => 'test.png',
SUBPAGES => [1,2]);
$pl->xyplot ($x, $y, SUBPAGE => 1);
$pl->xyplot ($a, $b, SUBPAGE => 2);
=head3 SYMBOL
Specify which symbol to use when plotting C<< PLOTTYPE => 'POINTS' >>.
A large variety of symbols are available, see:
http://plplot.sourceforge.net/examples-data/demo07/x07.*.png, where * is 01 - 17.
You are most likely to find good plotting symbols in the 800s:
http://plplot.sourceforge.net/examples-data/demo07/x07.06.png
=head3 SYMBOLSIZE
Specify the size of symbols plotted in multiples of the default size (1).
Value are real numbers from 0 to large.
=head3 TEXTPOSITION
Specify the placement of text. Either relative to border, specified as:
[$side, $disp, $pos, $just]
Where
side = 't', 'b', 'l', or 'r' for top, bottom, left and right
disp is the number of character heights out from the edge
pos is the position along the edge of the viewport, from 0 to 1.
just tells where the reference point of the string is: 0 = left, 1 = right, 0.5 = center.
or inside the plot window, specified as:
[$x, $y, $dx, $dy, $just]
Where
x = x coordinate of reference point of string.
y = y coordinate of reference point of string.
dx Together with dy, this specifies the inclination of the string.
The baseline of the string is parallel to a line joining (x, y) to (x+dx, y+dy).
dy Together with dx, this specifies the inclination of the string.
just Specifies the position of the string relative to its reference point.
If just=0, the reference point is at the left and if just=1,
it is at the right of the string. Other values of just give
intermediate justifications.
=for example
# Plot text on top of plot
$pl->text ("Top label", TEXTPOSITION => ['t', 4.0, 0.5, 0.5]);
# Plot text in plotting area
$pl->text ("Line label", TEXTPOSITION => [50, 60, 5, 5, 0.5]);
=head3 TITLE
Add a title on top of a plot.
=for example
# Plot text on top of plot
$pl->xyplot ($x, $y, TITLE => 'X vs. Y');
=head3 UNFILLED_BARS
For 'bargraph', if set to true then plot the bars as outlines
in the current color and not as filled boxes
=for example
# Plot text on top of plot
$pl->bargraph($labels, $values, UNFILLED_BARS => 1);
=head3 VIEWPORT
Set the location of the plotting window on the page.
Takes a four element array ref specifying:
xmin -- The coordinate of the left-hand edge of the viewport. (0 to 1)
xmax -- The coordinate of the right-hand edge of the viewport. (0 to 1)
ymin -- The coordinate of the bottom edge of the viewport. (0 to 1)
ymax -- The coordinate of the top edge of the viewport. (0 to 1)
You will need to use this to make color keys or insets.
=for example
# Make a small plotting window in the lower left of the page
$pl->xyplot ($x, $y, VIEWPORT => [0.1, 0.5, 0.1, 0.5]);
# Also useful in creating color keys:
$pl->xyplot ($x, $y, PALETTE => 'RAINBOW', PLOTTYPE => 'POINTS', COLORMAP => $z);
$pl->colorkey ($z, 'v', VIEWPORT => [0.93, 0.96, 0.15, 0.85]);
# Plot an inset; first the primary data and then the inset. In this
# case, the inset contains a selection of the orignal data
$pl->xyplot ($x, $y);
$pl->xyplot (where($x, $y, $x < 1.2), VIEWPORT => [0.7, 0.9, 0.6, 0.8]);
=head3 XBOX
Specify how to label the X axis of the plot as a string of option letters:
a: Draws axis, X-axis is horizontal line (y=0), and Y-axis is vertical line (x=0).
b: Draws bottom (X) or left (Y) edge of frame.
c: Draws top (X) or right (Y) edge of frame.
d: Plot labels as date / time. Values are assumed to be seconds since the epoch (as used by gmtime).
f: Always use fixed point numeric labels.
g: Draws a grid at the major tick interval.
h: Draws a grid at the minor tick interval.
i: Inverts tick marks, so they are drawn outwards, rather than inwards.
l: Labels axis logarithmically. This only affects the labels, not the data,
and so it is necessary to compute the logarithms of data points before
passing them to any of the drawing routines.
m: Writes numeric labels at major tick intervals in the
unconventional location (above box for X, right of box for Y).
n: Writes numeric labels at major tick intervals in the conventional location
(below box for X, left of box for Y).
s: Enables subticks between major ticks, only valid if t is also specified.
t: Draws major ticks.
The default is C<'BCNST'> which draws lines around the plot, draws major and minor
ticks and labels major ticks.
=for example
# plot two lines in a box with independent X axes labeled
# differently on top and bottom
$pl->xyplot($x1, $y, XBOX => 'bnst', # bottom line, bottom numbers, ticks, subticks
YBOX => 'bnst'); # left line, left numbers, ticks, subticks
$pl->xyplot($x2, $y, XBOX => 'cmst', # top line, top numbers, ticks, subticks
YBOX => 'cst', # right line, ticks, subticks
BOX => [$x2->minmax, $y->minmax]);
=head3 XERRORBAR
Used only with L</xyplot>. Draws horizontal error bars at all points (C<$x>, C<$y>) in the plot.
Specify a PDL containing the same number of points as C<$x> and C<$y>
which specifies the width of the error bar, which will be centered at (C<$x>, C<$y>).
=head3 XLAB
Specify a label for the X axis.
=head3 XTICK
Interval (in graph units/world coordinates) between major x axis tick marks.
Specify zero (default) to allow PLplot to compute this automatically.
=head3 YBOX
Specify how to label the Y axis of the plot as a string of option letters.
See L</XBOX>.
=head3 YERRORBAR
Used only for xyplot. Draws vertical error bars at all points (C<$x>, C<$y>) in the plot.
Specify a PDL containing the same number of points as C<$x> and C<$y>
which specifies the width of the error bar, which will be centered at (C<$x>, C<$y>).
=head3 YLAB
Specify a label for the Y axis.
=head3 YTICK
Interval (in graph units/world coordinates) between major y axis tick marks.
Specify zero (default) to allow PLplot to compute this automatically.
=head3 ZRANGE
For L</xyplot> (when C<COLORMAP> is specified), for
L</shadeplot> and for L</colorkey>.
Normally, the range of the Z variable (color) is taken as
C<< $z->minmax >>. If a different range is desired,
specify it in C<ZRANGE>, like so:
$pl->shadeplot ($z, $nlevels, PALETTE => 'GREENRED', ZRANGE => [0,100]);
or
$pl->xyplot ($x, $y, PALETTE => 'RAINBOW', PLOTTYPE => 'POINTS',
COLORMAP => $z, ZRANGE => [-90,-20]);
$pl->colorkey ($z, 'v', VIEWPORT => [0.93, 0.96, 0.13, 0.85],
ZRANGE => [-90,-20]);
=head1 METHODS
These are the high-level, object oriented methods for PLplot.
=head2 new
=for ref
Create an object representing a plot.
=for usage
Arguments:
none.
Supported options:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
=for example
my $pl = PDL::Graphics::PLplot->new(DEV => 'png', FILE => 'test.png');
=head2 setparm
=for ref
Set options for a plot object.
=for usage
Arguments:
none.
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
$pl->setparm (TEXTSIZE => 2);
=head2 xyplot
=for ref
Plot XY lines and/or points. Also supports color scales for points.
This function works with bad values. If a bad value is specified for
a points plot, it is omitted. If a bad value is specified for a line
plot, the bad value makes a gap in the line. This is useful for
drawing maps; for example C<$x> and C<$y> can be the continent boundary
latitude and longitude.
=for usage
Arguments:
$x, $y
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
$pl->xyplot($x, $y, PLOTTYPE => 'POINTS', COLOR => 'BLUEVIOLET', SYMBOL => 1, SYMBOLSIZE => 4);
$pl->xyplot($x, $y, PLOTTYPE => 'LINEPOINTS', COLOR => [50,230,30]);
$pl->xyplot($x, $y, PALETTE => 'RAINBOW', PLOTTYPE => 'POINTS', COLORMAP => $z);
=head2 stripplots
=for ref
Plot a set of strip plots with a common X axis, but with different Y axes.
Looks like a stack of long, thin XY plots, all line up on the same X axis.
=for usage
Arguments:
$xs -- 1D PDL with common X axis values, length = N
$ys -- reference to a list of 1D PDLs with Y-axis values, length = N
or 2D PDL with N x M elements
-- OR --
$xs -- reference to a list of 1D PDLs with X-axis values
$ys -- reference to a list of 1D PDLs with Y-axis values
%opts -- Options hash
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
my $x = sequence(20);
my $y1 = $x**2;
my $y2 = sqrt($x);
my $y3 = $x**3;
my $y4 = sin(($x/20) * 2 * $pi);
$ys = cat($y1, $y2, $y3, $y4);
$pl->stripplots($x, $ys, PLOTTYPE => 'LINE', TITLE => 'functions',
YLAB => ['x**2', 'sqrt(x)', 'x**3', 'sin(x/20*2pi)'],
COLOR => ['GREEN', 'DEEPSKYBLUE', 'DARKORCHID1', 'DEEPPINK'], XLAB => 'X label');
# Equivalent to above:
$pl->stripplots($x, [$y1, $y2, $y3, $y4],
PLOTTYPE => 'LINE', TITLE => 'functions',
YLAB => ['x**2', 'sqrt(x)', 'x**3', 'sin(x/20*2pi)'],
COLOR => ['GREEN', 'DEEPSKYBLUE', 'DARKORCHID1', 'DEEPPINK'], XLAB => 'X label');
# Here's something a bit different. Notice that different xs have
# different lengths.
$x1 = sequence(20);
$y1 = $x1**2;
$x2 = sequence(18);
$y2 = sqrt($x2);
$x3 = sequence(24);
$y3 = $x3**3;
my $x4 = sequence(27);
$a = ($x4/20) * 2 * $pi;
my $y4 = sin($a);
$xs = [$x1, $x2, $x3, $x4];
$ys = [$y1, $y2, $y3, $y4];
$pl->stripplots($xs, $ys, PLOTTYPE => 'LINE', TITLE => 'functions',
YLAB => ['x**2', 'sqrt(x)', 'x**3', 'sin(x/20*2pi)'],
COLOR => ['GREEN', 'DEEPSKYBLUE', 'DARKORCHID1', 'DEEPPINK'], XLAB => 'X label');
In addition, COLOR may be specified as a reference to a list of colors. If
this is done, the colors are applied separately to each plot.
Also, the options Y_BASE and Y_GUTTER can be specified. Y_BASE gives the Y offset
of the bottom of the lowest plot (0-1, specified like a VIEWPORT, defaults to 0.1) and Y_GUTTER
gives the gap between the graphs (0-1, default = 0.02).
=head2 colorkey
=for ref
Plot a color key showing which color represents which value
=for usage
Arguments:
$range : A PDL which tells the range of the color values
$orientation : 'v' for vertical color key, 'h' for horizontal
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
# Plot X vs. Y with Z shown by the color. Then plot
# vertical key to the right of the original plot.
$pl->xyplot ($x, $y, PALETTE => 'RAINBOW', PLOTTYPE => 'POINTS', COLORMAP => $z);
$pl->colorkey ($z, 'v', VIEWPORT => [0.93, 0.96, 0.15, 0.85]);
=head2 shadeplot
=for ref
Create a shaded contour plot of 2D PDL 'z' with 'nsteps' contour levels.
Linear scaling is used to map the coordinates of Z(X, Y) to world coordinates
via the L</BOX> option.
=for usage
Arguments:
$z : A 2D PDL which contains surface values at each XY coordinate.
$nsteps : The number of contour levels requested for the plot.
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
# vertical key to the right of the original plot.
# The BOX must be specified to give real coordinate values to the $z array.
$pl->shadeplot ($z, $nsteps, BOX => [-1, 1, -1, 1], PALETTE => 'RAINBOW', ZRANGE => [0,100]);
$pl->colorkey ($z, 'v', VIEWPORT => [0.93, 0.96, 0.15, 0.85], ZRANGE => [0,100]);
=head2 histogram
=for ref
Create a histogram of a 1-D variable.
=for usage
Arguments:
$x : A 1D PDL
$nbins : The number of bins to use in the histogram.
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
$pl->histogram ($x, $nbins, BOX => [$min, $max, 0, 100]);
=head2 histogram1
=for ref
Create a histogram of a 1-D variable. This alternative to 'histogram'
creates filled boxes and also handles Y-axis scaling better.
=for usage
Arguments:
$x : A 1D PDL
$nbins : The number of bins to use in the histogram.
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
$pl->histogram1 ($x, $nbins, COLOR => 'GREEN');
=head2 bargraph
=for ref
Simple utility to plot a bar chart with labels on the X axis.
The usual options can be specified, plus one other: MAXBARLABELS
specifies the maximum number of labels to allow on the X axis.
The default is 20. If this value is exceeded, then every other
label is plotted. If twice MAXBARLABELS is exceeded, then only
every third label is printed, and so on.
if UNFILLED_BARS is set to true, then plot the bars as outlines
and not as filled rectangles.
A stacked bar graph can be created if the STACKED_BAR_COLORS
option is set. The option takes a reference to a perl list of
color names or RGB triplets. If this option is set, then $x should
not be a 1-D PDL of N bar heights, but a 2D PDL of NxM where N is the
number of bars and M is the number of colors in STACKED_BAR_COLORS.
=for usage
Arguments:
$labels -- A reference to a perl list of strings.
$values -- A PDL of values to be plotted.
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
$labels = ['one', 'two', 'three'];
$values = pdl(1, 2, 3);
# Note if TEXTPOSITION is specified, it must be in 4 argument mode (border mode):
# [$side, $disp, $pos, $just]
#
# Where side = 't', 'b', 'l', or 'r' for top, bottom, left and right
# 'tv', 'bv', 'lv' or 'rv' for top, bottom, left or right perpendicular to the axis.
#
# disp is the number of character heights out from the edge
# pos is the position along the edge of the viewport, from 0 to 1.
# just tells where the reference point of the string is: 0 = left, 1 = right, 0.5 = center.
#
# The '$pos' entry will be ignored (computed by the bargraph routine)
$pl->bargraph($labels, $values, MAXBARLABELS => 30, TEXTPOSITION => ['bv', 0.5, 1.0, 1.0]);
# A stacked bar chart:
$labels = ['label1', 'label2', 'label3'];
$values = pdl([[50,40,60], # green bars
[20,10,30]]); # purple ([128, 0, 56]) bars
$pl->bargraph ($labels, $values, STACKED_BAR_COLORS => ['GREEN', [128, 0, 56]])
=head2 text
=for ref
Write text on a plot. Text can either be written
with respect to the borders or at an arbitrary location and angle
(see the L</TEXTPOSITION> entry).
=for usage
Arguments:
$t : The text.
Supported options:
All options except:
BACKGROUND
DEV
FILE
FRAMECOLOR
JUST
PAGESIZE
SUBPAGES
(These must be set in call to 'new'.)
=for example
$pl->text("Count", COLOR => 'PINK',
TEXTPOSITION => ['t', 3, 0.5, 0.5]); # top, 3 units out, string ref. pt in
# center of string, middle of axis
=head2 close
=for ref
Close a PLplot object, writing out the file and cleaning up.
=for usage
Arguments:
None
Returns:
Nothing
This closing of the PLplot object can be done explicitly though the
'close' method. Alternatively, a DESTROY block does an automatic
close whenever the PLplot object passes out of scope.
=for example
$pl->close;
=cut
# Colors (from rgb.txt) are stored as RGB triples
# with each value from 0-255
sub cc2t { [map {hex} split ' ', shift] }
our %_constants = (
BLACK => [ 0, 0, 0],
RED => [240, 50, 50],
YELLOW => [255,255, 0],
GREEN => [ 0,255, 0],
AQUAMARINE => [127,255,212],
PINK => [255,192,203],
WHEAT => [245,222,179],
GREY => [190,190,190],
BROWN => [165, 42, 42],
BLUE => [ 0, 0,255],
BLUEVIOLET => [138, 43,226],
CYAN => [ 0,255,255],
TURQUOISE => [ 64,224,208],
MAGENTA => [255, 0,255],
SALMON => [250,128,114],
WHITE => [255,255,255],
ROYALBLUE => cc2t('2B 60 DE'),
DEEPSKYBLUE => cc2t('3B B9 FF'),
VIOLET => cc2t('8D 38 C9'),
STEELBLUE1 => cc2t('5C B3 FF'),
DEEPPINK => cc2t('F5 28 87'),
MAGENTA => cc2t('FF 00 FF'),
DARKORCHID1 => cc2t('B0 41 FF'),
PALEVIOLETRED2 => cc2t('E5 6E 94'),
TURQUOISE1 => cc2t('52 F3 FF'),
LIGHTSEAGREEN => cc2t('3E A9 9F'),
SKYBLUE => cc2t('66 98 FF'),
FORESTGREEN => cc2t('4E 92 58'),
CHARTREUSE3 => cc2t('6C C4 17'),
GOLD2 => cc2t('EA C1 17'),
SIENNA1 => cc2t('F8 74 31'),
CORAL => cc2t('F7 65 41'),
HOTPINK => cc2t('F6 60 AB'),
LIGHTCORAL => cc2t('E7 74 71'),
LIGHTPINK1 => cc2t('F9 A7 B0'),
LIGHTGOLDENROD => cc2t('EC D8 72'),
);
# a hash of subroutines to invoke when certain keywords are specified