Debian Codegraph @

examples/std_pgplot.pl

raw symbols SCIP
1 =head1 NAME
2
3 std_pgplot - Examples of PGPLOT routines.
4
5 =head1 SYNOPSIS
6
7 std_pgplot.pl
8
9 =head1 DESCRIPTION
10
11 This file is intended to show the use of PGPLOT routines using the
12 standard interface. See the C<pgplot.pl> file for an object-oriented
13 version of the same (the object-oriented interface is strongly recommended.)
14
15 =cut
16
17 use PDL;
18 use PDL::Graphics::PGPLOT;
19
20
21 ##
22 ## Test all PGPLOT routines.
23 ##
24 my $random = grandom(1000);
25 my ($xc, $yc)=hist $random;
26 my $x=zeroes(100)->xlinvals(-5,5);
27 my $y=exp(-$x*$x/2);
28
29
30
31 print "First we will test all functions in PGPLOT.\n";
32 print "We also will show most of the options\n";
33 print "After each plot - please press <CR> to proceed - type q<CR> to quit.\n";
34
35 function_to_do ('dev(), env(), hold(), release(), bin(), line()');
36
37 my $win1 = dev('/xw', {Aspect => 1, WindowWidth => 7});
38 env(-5, 5, 0, max($yc)*1.1, {Axiscolour => 'Red'});
39 bin $xc, $yc;
40 hold;
41 line $x, $y*max($yc), {LineSty => 'Dashed', Color => 'Blue', LineWidth => 5};
42 release;
43 #close_window($win);
44
45 next_plot();
46 function_to_do ('errb() & points()');
47 my $xd = pdl(1,3,7,10);
48 my $yd = pdl(2, 7,5,7);
49 my $dy = sqrt($yd**2/12+0.2**2);
50 env(0, 15, 0, 10, {Xtitle => 'X-data', Ytitle=>'Y-data',
51 Title => 'An example of errb and points', Font => 'Italic'});
52 points $xd, $yd;
53 errb $xd, $yd, $dy;
54 release;
55
56 next_plot();
57 function_to_do('line() poly(), cont(), label_axes() and text()');
58 my $im = rvals(100, 100);
59 cont $im, {NCOn => 4};
60 hold;
61 line pdl(0, 50), pdl(0, 50), {Color => 'RED'};
62 my $px = pdl(20, 40, 40, 20, 20);
63 my $py = pdl(80, 80, 100, 100, 80);
64 poly $px, $py, {Fill => 3};
65 poly $px, $py, {Color=>'Red', Fill => 3, Hatch => {Phase => 0.5}};
66 label_axes('X-direction', 'Y-direction', 'Title', {Color => 'Yellow'});
67
68 text 'Towards the centre', 24, 25, {Justification => 0.5, Angle=>45,
69 Font => 'Italic'};
70
71
72 next_plot();
73 function_to_do('imag(), ctab(), hi2d and several panels');
74
75 $win1= dev('/xw', 2, 2, {Aspect => 0.5, CharSize => 2});
76 imag $im, {Transform => pdl([0, 0.1, 0, 0, 0, 0.1])};
77 imag1 $im, {PIX => 1, ITF=>'Sqrt'};
78 ctab('Fire');
79 imag $im;
80 hold;
81 cont $im, {Color => 'Yellow'};
82 release;
83 hi2d $im->slice('0:-1:10,0:-1:10');
84
85 next_plot();
86 function_to_do('Several plot windows. focus_window(), window_list()');
87
88 close_window($win1);
89 $win1 = dev('/xw', {Aspect => 1, AxisColour => 'Blue', WindowName => 'First',
90 WindowWidth => 6});
91 my $win2 = dev('/xw', {Aspect => 0.618, AxisColour => 'Red',
92 WindowWidth => 6, NewWindow => 1});
93
94 focus_window('First');
95 line $x, $x**2;
96 hold;
97 focus_window($win2);
98 my $ii = which($x>=0);
99 points $x->index($ii), sqrt($x->index($ii));
100 hold;
101 line $x->index($ii), sqrt($x->index($ii)), {Color => 'Red', Linestyle => 'dashed'};
102 release;
103 focus_window($win1);
104 points $x, $x**2+$x->grandom();
105 release;
106
107 my ($nums, $names)=window_list();
108 print "Window list:\n";
109 for (my $i=0; $i <= $#$nums; $i++) {
110 print " $$nums[$i]: $$names[$i]\n";
111 }
112
113
114 next_plot();
115 function_to_do('legend(), cursor()');
116
117 close_window($win2);
118
119 legend ['Parabola', 'Scatter points'], -2, 20,
120 {Width => 5, LineStyle => ['Solid', undef], Symbol => [undef, 'Default']};
121
122
123 print "Select a point using the cursor:\n";
124 my ($xp, $yp)=cursor({Type => 'CrossHair'});
125 print "(X, Y)=($xp, $yp)\n";
126
127 next_plot();
128
129 function_to_do('circle(), ellipse(), rectangle() and arrow()');
130
131 dev('/xs', {Aspect => 1, WindowWidth => 6});
132 env(0, 100, 0,100);
133 circle(50, 50, 10, {Fill => 'Outline'});
134 ellipse(40, 20, {MajorAxis => 30, MinorAxis=> 10, Theta => 30*3.14/180, Colour => 'Red'});
135 rectangle(70, 70, {XSide => 10, Angle => 45*3.14/180});
136
137 next_plot();
138
139 close_window($win1);
140
141 $win1 = dev('/xw', 2, 2, {Aspect => 1});
142 line $x, $y;
143 bin $xc, $yc, {Panel => 3};
144 env(0, 1, 0, 1, {Axis => 'Box'});
145 text "That's all folks!", 0.5, 0.5, {Justification => 0.5, CharSize => 3,
146 Color => 'Yellow'};
147
148 next_plot();
149
150
151 sub function_to_do {
152
153 print "\n**************************\n";
154 print "* $_[0]\n";
155 print "**************************\n\n";
156
157 }
158
159
160 sub next_plot {
161 my $message = shift;
162
163 $message ||='';
164
165 print $message."\n";
166 my $in = <STDIN>;
167
168 if ($in =~ /^q/i) {
169 exit;
170 }
171
172
173 }