-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_plot.i
1659 lines (1496 loc) · 54 KB
/
my_plot.i
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
if(_PRINT) write,"#include \"plot.i\"";
local plot;
/* DOCUMENT plot.i -- Additional routines for plotting in Yorick.
Provides routines:
* - pla: plot several curves at the same time;
* - plp: plot points/error bars;
* - plpa: plot several set of points/error bars at the same times
* - plh: plot in an "histogram" style;
* - pls: plot surface as a filled mesh with contours;
* - pl3s: plot 3D surface;
* - pl3dj: plot disjoint lines in 3D space;
* - pl3t: plot text in 3D space;
*
* Copyright (c) 1996-1999, Eric THIEBAUT.
* See the file "LICENSE" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* History:
* Jan, 2003 LeBouquin: add the function plpa
* Dec, 2003 LeBouquin: add contour plot in color_bar,add keyword edges
* Nov, 2003 LeBouquin: add vline option in plh;
* Nov, 2003 LeBouquin: add multidimentional option in pla
* Nov, 2003 LeBouquin: add dX and dY in pla
* $Id: plot.i,v 1.10 2002/05/14 10:03:49 eric Exp $
* $Log: plot.i,v $
* Revision 1.10 2002/05/14 10:03:49 eric
* - plp: use directly plfp instead of plmk to plot symbols and ticks.
* - plp: draw each symbol inside a unit circle so that they look the
* same size.
* - plp: new "star" symbol (SYMBOL=8) and draw polygon for SYMBOL>=9.
* - plp: new keywords XLO, XHI, YLO, YHI to draw non-symmetrical error
* bars and FILL to draw filled symbols.
* - plp: removed unused keyword HIDE.
*
* Revision 1.9 2001/11/15 09:46:19 eric
* - plp: use plmk to plot symbols and ticks.
* - plp: change usage of keywords SYMBOL and SIZE.
* - plp: remove keyword ASPECT.
*
* Revision 1.8 2001/06/21 12:45:17 eric
* - fix indentation and floating point representation.
*
* Revision 1.7 1997/04/03 15:52:39 eric
* Added routines color_bar and pl_fc.
*
* Revision 1.6 1996/11/22 11:42:02 eric
* - Add keyword ASPECT for plp.
*
* 02/20/96 Eric THIEBAUT: plp;
* 02/20/96 release 1.1.
* 02/21/96 Eric THIEBAUT: plh;
* 02/21/96 release 1.2.
* 02/21/96 Christophe PICHON and Eric THIEBAUT: pla;
* 03/04/96 Eric THIEBAUT (from routines written by Christophe PICHON
* and David MUNRO): pl3s, pl3dj pl3t;
* 03/04/96 release 1.3.
* 03/04/96 Eric THIEBAUT: added more symbols in plp;
* 24/03/96 Eric THIEBAUT: added "box" keyword in pl3s and fix some bugs;
* 24/03/96 release 1.4.
* May 3, 1996 by Eric THIEBAUT: added point symbol in routine plp;
SEE ALSO:
*/
/*---------------------------------------------------------------------------*/
func pl_fc(z, y, x, ireg, levs=, legend=, hide=, type=, width=, color=,
colors=, smooth=, marks=, marker=, mspace=, mphase=,
triangle=, region=)
{
d= dimsof(z);
if (d(1) != 2)
error, "expecting a 2D array for Z";
nx= d(2);
ny= d(3);
if (is_void(x))
x= span(1, nx, nx)(,-:1:ny);
else if (dimsof(x)(1) == 1)
x= x(,-:1:ny);
if (is_void(y))
y= span(1, ny, ny)(-:1:nx,);
else if (dimsof(y)(1) == 1)
y= y(-:1:nx,);
if (is_void(levs)) {
zmin= min(z);
zmax= max(z);
if (zmin >= zmax) levs= zmin;
else levs= zmin+indgen(9)*0.1*(zmax-zmin);
}
plfc, z, y, x, ireg, levs=levs, colors=colors,
triangle=triangle, region=region;
plc, z, y, x, ireg, levs=levs, legend=legend, hide=hide, type=type,
width=width, color=color, smooth=smooth, marks=marks, marker=marker,
mspace=mspace, mphase=mphase, triangle=triangle, region=region;
}
/*----------------------------------------------------------------------*/
func color_bar(levs, colors, vert=, labs=, adjust=, ecolor=, edges=,
height=, vport=, format=, font=, flip=)
/* DOCUMENT color_bar
or color_bar, levs, colors
Draw a color bar below the current coordinate system. If LEVS is
not specified uses plfc_levs (set by previous call to plfc). If
COLORS is specified, it should have one more value than LEVS,
otherwise equally spaced colors are chosen, or plfc_colors if
plfc_levs was used. With the vert=1 keyword the color bar appears
to the left of the current coordinate system (vert=0 is default).
By default, color_bar will attempt to label some of the color
interfaces. With the labs= keyword, you can force the labelling
algorithm as follows: labs=0 supresses all labels, labs=n forces
a label at every nth interface, labs=[i,n] forces a label at every
nth interface starting from interface i (0<=i<=numberof(LEVS)).
You can specify the viewport coordinates by keyword
VPORT=[xmin,xmax,ymin,ymax]; by default the colorbar is drawn next to
the current viewport. You can use the ADJUST keyword to move the bar
closer to (adjust<0) or further from (adjust>0) the viewport.
You can specify the string format for labels with keyword FORMAT (default
"%g"), the font type with keyword FONT and the font
height with keyword HEIGHT.
SEE ALSO: plfc
*/
{
if(is_void(edges)) edges=0;
if(is_void(flip)) flip=0;
if (is_void(levs)) {
if (is_void(plfc_levs)) error, "no levels specified";
levs= plfc_levs;
n= numberof(levs)+1;
if (is_void(colors)) colors= plfc_colors;
}
else {
if(numberof(levs)==2) levs = span(levs(1),levs(2),200);
n= numberof(levs)+1;
if (is_void(colors)) colors= bytscl(span(1,n,n),cmin=0.5,cmax=n+0.5);
}
if (n != numberof(colors))
error, "numberof(colors) must be one more than numberof(levs)";
if (is_void(vport)) vport= viewport();
if (is_void(adjust)) adjust= 0.0;
dx= dy= 0.0;
if (vert) {
x= (vport(2)+adjust+[0.022,0.042])(-:1:n+1,); x0=x(1,1);x1=x(1,0);
dx= 0.005;
y= span(vport(3),vport(4),n+1)(,-:1:2); y0=y(1,1);y1=y(0,1);
} else {
y= (vport(3)-adjust-[0.045,0.065])(-:1:n+1,); y0=y(1,1);y1=y(1,0);
dy= -0.005;
x= span(vport(1),vport(2),n+1)(,-:1:2); x0=x(1,1);x1=x(0,1);
}
sys= plsys(0);
plf,[colors],y,x,edges=edges,ecolor=ecolor, legend="";
plg,[y0,y0,y1,y1],[x0,x1,x1,x0], closed=1,
marks=0,color=ecolor,width=1,type=1,legend="";
plsys, sys;
if (is_void(labs) || labs(0)>0) {
if (numberof(levs)>1) {
dz= levs(dif);
if (numberof(dz)!=numberof(levs)-1 ||
anyof((dz>0.0)!=(dz(1)>0.0)) || !dz(1))
error, "levs must be monotone 1D";
levs= levs(1:0);
levs= grow([2*levs(1)-levs(2)],levs,[2*levs(0)-levs(-1)]);
} else {
levs= double(levs(1));
if (!levs) levs= [-1.0,levs,1.0];
else levs= [0.0,levs,2*levs];
}
if (numberof(labs)<2) {
if (is_void(labs)) labs= (n-1)/4 + 1;
orig= where(levs<1.0e-9*max(levs(dif)));
if (numberof(orig)==1) labs= [orig(1)%labs,labs];
else labs= [(n%labs)/2,labs];
}
list= where(indgen(0:n)%labs(2)==labs(1));
// CP : update in case we don't want to plot the 0 tick
if (!numberof(list)) {
list= where(indgen(0:n)%labs(2)==0);
list = list(2:) ;
}
info, x ;
x= x(list,);
y= y(list,);
if (is_void(format)) format= "%3.2g";
labs= strtrim(swrite(format=format,levs(list)));
plsys, 0;
if (flip) {
pldj, x(,2)-4*dx,y(,1),x(,2)-6*dx,y(,1)-dy, legend=""; // flip either x or y : x for HD163_pola
} else {
pldj, x(,2),y(,2),x(,2)+dx,y(,2)+dy, legend="";
}
plsys, sys;
if (flip) {
//plt1, labs,x(,2)+2*dx,y(,1)-5*dy, justify=(vert?"CH":"CT"),height=height,font=font;
//plt1, labs,x(,2),y(,1)-5*dy, justify=(vert?"CH":"CT"),height=height,font=font; // for HD163 planet
plt1, labs,x(,2)-9*dx,y(,1)-5*dy, justify=(vert?"CH":"CT"),height=height,font=font; // for HD163 pola
} else {
plt1, labs,x(,2)+3*dx,y(,2)+2*dy, justify=(vert?"CH":"CT"),height=height,font=font;
}
}
}
/*----------------------------------------------------------------------*/
func pla(y, x, every=, legend=, hide=, type=, width=, color=, closed=, smooth=,
marks=, marker=, mspace=, mphase=, msize=, rays=, arrowl=, arroww=,
rspace=, rphase=, dx=, dy=, dtype=, tosys=)
{
/* DOCUMENT pla, y, x
or pla, y
Plot the buddle of curves Y versus X labelled by the last indice.
Y must be 2-dimensional, and X may be 2-dimensional, 1-dimensional
or omitted. If X is 2-dimensional, it must have the same dimensions
as Y and Y(,i) versus X(,i) is plotted for each last indice i. If
X is 1-dimensional, it must have the same length as the 1st dimension
of Y and Y(,i) versus X is plotted for each last indice i. If X is
omitted, it defaults to [1, 2, ..., numberof(Y(,1))].
The plotting keywords of plg are accepted. Most of then could be
array of the same lenght as the secund dimension of y
he optional keyword
every=N which can be used to plot every N curves in the bundle
(default N=1).
The dx= and dy= keyword command X and Y errors bars
(could be 2D array). The type of the bars are command by dtype=
EXAMPLE
x =span(0,1,25)(,-:1:25);
pla, x*transpose(x), marks=0, every=3;
*/
if(typeof(y) == "complex") y=[y.re,y.im];
if (is_void(every)) {
n= 1;
} else if (numberof(every)!=1 || (n= long(every(1))) <= 0) {
error, "EVERY must be a scalar >= 1";
}
if (dimsof(y)(1) == 1) {y = [y];}
y = y(,*);
imax= dimsof(y)(3);
if (is_void(x)) {
x2d= 0N;
} else {
x2d= dimsof(x)(1) >= 2;
}
// default for x
if(is_void(x)) x=indgen(1:numberof(y(, 1)));
// loop on i
for(i= (n+1)/2; i <= imax; i+= n) {
// test on x
px= x2d ? &x(,i) : &x;
// test on scalar keyword
ptype= numberof(type)(1)>=1 ? &type(i%numberof(type)) : &type;
pmarker= numberof(marker)(1)>=1 ? &marker(i%numberof(marker)) : ▮
pmarks= numberof(marks)(1)>=1 ? &marks(i%numberof(marks)) : &marks;
pwidth= numberof(width)(1)>=1 ? &width(i%numberof(width)) : &width;
if (numberof(color) && dimsof(color)(1)==1)
pcolor= numberof(color)(1)>=1 ? &color(i%numberof(color)) : &color;
else if (!numberof(color)) pcolor=&[];
else
pcolor =numberof(color)(1,)>=1 ? &color(,i%numberof(color)) : &color;
plegend=numberof(legend)(1)>=1 ? &legend(i%numberof(legend)) : &legend;
pmsize= numberof(msize)(1)>=1 ? &msize(i%numberof(msize)) : &msize;
pdtype= numberof(dtype)(1)>=1 ? &dtype(,i%numberof(dtype)) : &dtype;
ptosys= numberof(tosys) ? tosys(i%numberof(tosys)) : [];
// test on array keyword
pdx = (!is_void(dx) && dimsof(dx)(1)>=2) ? &dx(,i) : &dx;
pdy = (!is_void(dy) && dimsof(dy)(1)>=2) ? &dy(,i) : &dy;
plsys, ptosys;
plg, y(, i), *px, legend=*plegend, hide=hide, type=*ptype, width=*pwidth,
color=*pcolor, closed=closed, smooth=smooth, marks=*pmarks,
marker=*pmarker,
mspace=mspace, mphase=mphase, rays=rays, arrowl=arrowl, arroww=arroww,
rspace=rspace, rphase=rphase, msize=*pmsize;
if(!is_void(*pdy))
pldj, *px, y(, i)-*pdy, *px, y(, i)+*pdy, color=*pcolor, width=*pwidth,
type=*pdtype;
if(!is_void(*pdx))
pldj, *px-*pdx, y(, i), *px+*pdx, y(, i), color=*pcolor, width=*pwidth,
type=*pdtype;
}
}
/*----------------------------------------------------------------------*/
func pls_mesh(&x, &xx, d, which=, inhibit=)
/* DOCUMENT err_msg= pls_mesh(x, xx, dimsof(z), which=1/2, inhibit=1/2)
build X and/or XX arrays of coordinates (abscissa if last argument is
0/nil; otherwise ordinate) for 2-D array Z. Normally, the returned
value is string(0) otherwise it is an error message.
X is input and output, it will have the same shape as Z and will be
suitable for contour plots. XX is purely output, it will have 1 more
element than Z in each dimension and will be suitable for mesh plots.
In other words, X(i,j) will furnish the coordinate of the centre of
cell Z(i,j) whereas XX(i,j), XX(i,j+1), XX(i+1,j) and XX(i+1,j+1)
will give the coordinates of the corners of cell Z(i,j).
Assuming the length of Z along the considered dimension is N
(N must be >= 2) there are 3 possibilities:
(1) if X is a vector with N elements or has the same shape as Z,
then X is considered to give the coordinates at the centre of Z
cells: X is unchanged and output XX is build by interpolating
(and extrapolating at the edges) X ;
(2) if X is a vector with N+1 elements or has 1 more element than Z
in each dimension, then X is considered to give the coordinates
at the corners of Z cells: output XX is set to input X and
output X is build by interpolating output XX;
(3) if X is nil, it defaults to [0.5, 1.5, ..., N-0.5] and XX
defaults to [0, 1, ..., N] along the considered dimension.
Finally, if X is 1-D, it is expanded in the other direction.
If keyword WHICH is 1 (the default), abscissa is the dimension of
interest; otherwise WHICH must be 2 and ordinate is the dimension
of interest.
If keyword INHIBIT is 1, then only X output is computed; if INHIBIT
is 2 then only XX output is computed.
SEE ALSO: pls, pl3s, plmesh.
*/
{
xx= [];
if (is_void(which))
which= 1;
do_x= inhibit != 1;
do_xx= inhibit != 2;
expand=1;
if (d(1) != 2 || anyof(d < 2))
return "Z must be 2-dimensional and have at least 2-by-2 elements";
n1= d(2);
n2= d(3);
n= d(which+1);
if (is_void((dx= dimsof(x)))) {
if (do_x)
x= span(0.5, n-0.5, n);
if (do_xx)
xx= span(0, n, n+1);
} else if (dx(1) == 1) {
if (dx(2) == n) {
if (do_xx) {
xx= x(pcen);
xx(1)= 2.0 * x(1) - x(2);
xx(0)= 2.0 * x(0) - x(-1);
}
} else if (dx(2) == n+1) {
xx= x;
x= do_x ? xx(zcen) : [];
}
} else if (dx(1) == 2) {
expand= 0;
if (allof(dx == d)) {
if (do_xx) {
t= x(pcen,);
t(1,)= 2.0 * x(1,) - x(2,);
t(0,)= 2.0 * x(0,) - x(-1,);
xx= t(,pcen);
xx(,1)= 2.0 * t(,1) - t(,2);
xx(,0)= 2.0 * t(,0) - t(,-1);
t= [];
}
} else if (allof(dx == d + [0,1,1])) {
xx= x;
x= do_x ? xx(zcen,zcen) : [];
}
}
if (is_void(xx) && is_void(x)) {
return "X, Y and Z are not compatible";
}
if (expand) {
if (which == 1) {
if (do_x)
x= x(,-:1:n2);
if (do_xx)
xx= xx(,-:1:n2+1);
} else {
if (do_x)
x= x(-:1:n1,);
if (do_xx)
xx= xx(-:1:n1+1,);
}
}
return string(0);
}
func pls(z, y, x, cbar=, viewport=, title=, xtitle=, ytitle=,
legend=, hide=, top=, cmin=, cmax=, edges=, ecolor=, ewidth=,
height=, font=, levs=, nlevs=, type=, width=, color=,
marks=, marker=, mspace=, mphase=, smooth=)
/* DOCUMENT pls, z, y, x
or pls, z
draws surface plot of Z versus (X,Y) as a filled mesh with
optional contours. The Z array must be a 2-dimensional array,
see documentation of pls_mesh for the meaning of X and Y.
If keyword CBAR is set to non-zero, a color bar is drawn on the
right of the plot. The current viewport (in NDC) may be
specified with keyword VIEWPORT, default is:
[0.19, 0.60, 0.44, 0.85].
The appearance of the filled mesh can be modified by means of
keywords: LEGEND, HIDE, TOP, CMIN, CMAX, EDGES, ECOLOR and EWIDTH
(see plf documentation).
Optional contour plot of Z may be superimposed by either keyword
NLEVS to set the number of contours or by with keyword LEVS to
specify the level values. The appearance of the contour plot can
be modified by means of keywords: LEGEND, HIDE, TYPE, WIDTH,
COLOR, MARKS, MARKER, MSPACE, MPHASE and SMOOTH (see plc
documentation).
SEE ALSO: pls_mesh, pl3s, plc, plf, plmesh.
*/
{
local r, g, b; // these variables are used to query colors
local xx, yy;
/*
* Set some defaults.
*/
if (is_void(edges))
edges= 0;
if (is_void(height)) {
height= 12;
small = 10;
} else {
s= [8,10,12,14,18,24];
i= where(height == s);
if (numberof(i) != 1)
error, "bad font HEIGHT";
i= i(1);
small= i > 1 ? s(i-1) : height;
}
if (numberof(levs)) {
nlevs= numberof(levs);
} else if (is_void(nlevs)) {
nlevs= 8;
}
/*
* Compute mesh coordinates.
*/
i= nlevs >= 1 ? 0 : 1;
if ((msg= pls_mesh(x, xx, dimsof(z), which=1, inhibit=i)) != string(0) ||
(msg= pls_mesh(y, yy, dimsof(z), which=2, inhibit=i)) != string(0))
error, msg;
/*
* Plot color bar and titles.
*/
vpmax= [0.127, 0.672, 0.363, 0.908];
if (numberof(viewport) != 4)
viewport= [0.19, 0.60, 0.44, 0.85]; // standard viewport
if (cbar) {
local r, g, b;
plsys, 0;
margin= vpmax(2)-viewport(2);
x0= viewport(2) + 0.7 * margin;
x1= viewport(2) + 0.9 * margin;
y0= viewport(3);
y1= viewport(4);
palette, r, g, b, query=1;
n= numberof(r);
r= g= b= [];
pli, char(indgen(n)-1)(-,), legend=string(0), x0, y0, x1, y1;
plg, [y0,y0,y1,y1,y0], [x0,x1,x1,x0,x0], legend=string(0), marks=0,
width=1;
plsys, 1;
}
xc= 0.5*(viewport(1)+viewport(2));
yc= 0.5*(viewport(3)+viewport(4));
if (!is_void(title)) {
plt, title, xc, viewport(4) + 0.9 * (vpmax(4) - viewport(4)), tosys=0,
legend=string(0), justify="CT", path=0,
font=font, height=height, opaque=opaque;
}
if (!is_void(xtitle)) {
plt, xtitle, xc, vpmax(3) + 0.05 * (viewport(3) - vpmax(3)), tosys=0,
legend=string(0), justify="CB", path=0,
font=font, height=small, opaque=opaque;
}
if (!is_void(ytitle)) {
plt, ytitle, vpmax(1) + 0.05 * (viewport(1) - vpmax(1)), yc, tosys=0,
legend=string(0), justify="LH", path=1,
font=font, height=small, opaque=opaque;
}
/*
* Plot filled mesh.
*/
plf, z, yy, xx, legend=legend, hide=hide,
top=top, cmin=cmin, cmax=cmax, edges=edges, ecolor=ecolor, ewidth=ewidth;
xx= yy= [];
/*
* Plot contours.
*/
if (nlevs) {
if (is_void(levs)) {
zmax= double(max(z));
zmin= double(min(z));
levs= zmin + (zmax-zmin) / double(nlevs+1) * indgen(nlevs);
}
plc, z, y, x, levs=levs, legend=legend, hide=hide, type=type, width=width,
color=color, marks=marks, marker=marker, mspace=mspace, mphase=mphase,
smooth=smooth;
}
}
/*----------------------------------------------------------------------*/
func plh(y, x, just=, legend=, hide=, type=, width=, color=, marks=, marker=,
mspace=, mphase=, vline=, ecolor=, bwidth=)
/* DOCUMENT plh, y, x
or plh, y
plots a graph of Y versus X in an "histogram" style (i.e., with
steps). Y and X must be 1-D arrays of equal length; if X is
omitted, it defaults to [1, 2, ..., numberof(Y)].
The optional keyword JUST set justification of the histogram:
JUST=1, 2 or 3 makes the graph be left justified, centered or
right justified respectively along X axis. Default is centered.
JUST= 4 --> justified with bars whose width is given by keyword bwidth.
Default is 0.5. 1.0 means touching bars.
The optional keyword VLINE=0 print vertical line betwen the steps.
Other plotting keywords (legend, hide, type, width, color, marks,
marker, mspace, and mphase) are passed to the plg routine.
SEE ALSO: plg, plm, plc, plv, plf, pli, plt, pldj, plfp
limits, logxy, range, fma, hcp
*/
{
if(is_void(marks)) marks=0;
if(is_void(type)) type="solid";
if(is_void(vline)) vline=0;
// parse/check arguments
if (!is_array(y) || dimsof(y)(1)!=1 || (n= numberof(y)) < 2)
error, "Y must be a vector of at least 2 elements";
if (is_void(x))
x= double(indgen(numberof(y)));
else if (!is_array(x) || dimsof(x)(1)!=1 || numberof(x) != n)
error, "X must be a vector of same length as Y";
if (is_void(just))
just= 2;
// build new X vector
n2= 2 * n;
n4 = 2*n2;
x2= array(double, n2);
x4= array(double, n4);
if (just == 1) {
// left justify
x2(1::2)= x;
x2(2:-1:2)= x(2:);
x2(0)= 2 * x(0) - x(-1);
} else if (just == 2) {
// center
d= 0.5 * x(dif);
dx= d(1);
grow, dx, d, d(0);
d= [];
x2(1::2)= x - dx(:-1);
x2(2::2)= x + dx(2:);
dx= [];
} else if (just == 3) {
// right justify
x2(1)= 2 * x(1) - x(2);
x2(2::2)= x;
x2(3::2)= x(:-1);
} else if (just == 4) {
// center
if (is_void(bwidth)) bwidth=0.5;
d= 0.5 * bwidth * x(dif);
dx= d(1);
grow, dx, d, d(0);
d= [];
x2(1::2)= x - dx(:-1);
x2(2::2)= x
x4(1::4) = x4(2::4) = x - dx(:-1);
x4(3::4) = x4(4::4) = x + dx(2:);
dx= [];
} else {
error, "bad value for JUST";
}
// build new Y vector
y2= array(double, n2);
y2(1::2)= y2(2::2)= y;
y4= array(double, n4);
y4(2::4) = y4(3::4) = y
//Filled graph :
if (!is_void(ecolor)) {
l = limits();
if (structof(ecolor) == string) {
n = where(ecolor == __pl_color_list);
if (numberof(n)!=1) error, "unrecognized color name: "+ecolor;
ecolor = char(-n(1));
} else if (structof(ecolor) != char) {
ecolor = char(ecolor);
}
if (just==4) {
plfp, array(ecolor,1) , _(y4,l(3),l(3)) , _(x4,x4(0),x4(1)), numberof(y4)+2;
} else {
plfp, array(ecolor,1) , _(y2,l(3),l(3)) , _(x2,x2(0),x2(1)), numberof(y2)+2;
}
}
// plot the graph
if (just==4) {
plg, y4, x4,
legend=legend, hide=hide, type=type, width=width, color=color,
marks=marks, marker=marker, mspace=mspace, mphase=mphase;
} else {
plg, y2, x2,
legend=legend, hide=hide, type=type, width=width, color=color,
marks=marks, marker=marker, mspace=mspace, mphase=mphase;
}
//================================
if(vline==1) {
l = limits();
pldj,x2,y2,x2,y2*0.+l(3),type=type, width=width, color=color;
}
if (0) {
dens = 3;
nb_point = 40;
dimx = numberof(x2-1)*dens;
test = array(int, nb_point , dimx);
ty = span(min(y2), max(y2), nb_point);
tx = y2(-:1:dens,)(*);
test = ty(-,) < tx; ou = where(test);
xp = span(min(x2), max(x2), dimx)(,-:1:nb_point)(*)(ou);
yp = ty(-:1:dimx,)(*)(ou);
plp, yp , xp , symbol=15, size=.3;
}
}
/*---------------------------------------------------------------------------*/
func plp(y, x, dx=, xlo=, xhi=, dy=, ylo=, yhi=, size=, symbol=, ticks=,
legend=, type=, width=, color=, fill=)
/* DOCUMENT plp, y, x
-or- plp, y, x, dx=sigma_x, dy=sigma_y
Plots points (X,Y) with symbols and/or error bars. X, and Y may have
any dimensionality, but must have the same number of elements. If X
is nil, it defaults to indgen(numberof(Y)).
Keyword SYMBOL may be used to choose the shape of each symbol:
0 nothing (just draw error bars if any)
1 square
2 cross (+ sign)
3 triangle
4 circle (hexagon)
5 diamond
6 cross (rotated 45 degrees) <- this is the default
7 triangle (upside down)
8 star
>=9 SYMBOL-side polygon
Keyword SIZE may be used to change the size of the symbols and tick
marks (SIZE acts as a multiplier, default value is 1.0).
If value of keyword FILL is true (non-nil and non-zero), symbols are
filled with COLOR (default is to draw open symbols).
Keywords XLO, XHI, YLO, and/or YHI can be used to indicate the bounds
of the optional error bars (default is to draw no error bars). Only
specified bounds get plotted as error bars. If value of keyword TICKS
is true (non-nil and non-zero), ticks get drawn at the endpoints of
the error bars. Alternatively, keywords DX and/or DY can be used to
plot error bars as segments from XLO=X-DX to XHI=X+DX and/or from
YLO=Y-DY to YHI=Y+DY. If keyword DX (respectively DY) is used, any
value of XLO and XHI (respectively YLO and YHI) is ignored.
The other keywords are the same as for pldj (TYPE is only used to draw
error bars):
KEYWORDS: legend, type, width, color.
SEE ALSO: pldj, plg, plm, plc, plv, plf, pli, plt, pldj, plfp, plmk,
limits, logxy, range, fma, hcp. */
{
/* NDC units for symbols/ticks (one pixel = 0.00125268 NDC at 75 DPI) */
u0 = 0.0; // zero
u1 = 0.00500214; // radius of about 5 pixels at 75 DPI
if (! is_void(size)) u1 *= size;
/* parse color */
if (is_void(color)) color = char(-2); /* fg */
if (structof(color) == string) {
n = where(color == __pl_color_list);
if (numberof(n)!=1) error, "unrecognized color name: "+color;
color = char(-n(1));
} else if (structof(color) != char) {
color = char(color);
}
/* default X */
if (is_void(x)) (x = array(double, dimsof(y)))(*) = indgen(numberof(y));
/* error bars */
if (is_void(dx)) {
err = (! is_void(xlo)) + 2*(! is_void(xhi));
} else {
xlo = x - dx;
xhi = x + dx;
err = 3;
}
if (err) {
pldj, (is_void(xlo) ? x : xlo), y, (is_void(xhi) ? x : xhi), y,
type=type, width=width, color=color;
if (ticks) {
xm = [ u0, u0];
ym = [-u1, u1];
if (err == 1) __plp, y, xlo;
else if (err == 2) __plp, y, xhi;
else __plp, [y, y], [xlo, xhi];
}
xhi = xlo = [];
}
if (is_void(dy)) {
err = (! is_void(ylo)) + 2*(! is_void(yhi));
} else {
ylo = y - dy;
yhi = y + dy;
err = 3;
}
if (err) {
pldj, x, (is_void(ylo) ? y : ylo), x, (is_void(yhi) ? y : yhi),
type=type, width=width, color=color;
if (ticks) {
xm = [-u1, u1];
ym = [ u0, u0];
if (err == 1) __plp, ylo, x;
else if (err == 2) __plp, yhi, x;
else __plp, [ylo, yhi], [x, x];
}
yhi = ylo = [];
}
/* symbols */
if (! symbol) {
if (is_void(symbol)) symbol = 6;
else return;
}
if (symbol == 1) {
/* square */
u2 = u1*sqrt(0.5);
xm = [-u2, u2, u2,-u2];
ym = [ u2, u2,-u2,-u2];
} else if (symbol == 2) {
/* + cross */
xm = [-u1, u1, u0, u0, u0, u0];
ym = [ u0, u0, u0, u1,-u1, u0];
fill = 0;
} else if (symbol == 3) {
/* triangle */
u2 = u1*0.5;
u3 = u1*sqrt(0.75);
xm = [u0, u3,-u3];
ym = [u1,-u2,-u2];
} else if (symbol == 4) {
/* hexagon */
u2 = u1*0.5;
u3 = u1*sqrt(0.75);
xm = [ u1, u2,-u2,-u1,-u2, u2];
ym = [ u0, u3, u3, u0,-u3,-u3];
} else if (symbol == 5) {
/* diamond */
xm = [u1, u0,-u1, u0];
ym = [u0, u1, u0,-u1];
} else if (symbol == 6) {
/* x cross (rotated 45 degrees) */
u2 = u1*sqrt(0.5);
xm = [u2,-u2, u0, u2,-u2, u0];
ym = [u2,-u2, u0,-u2, u2, u0];
fill = 0;
} else if (symbol == 7) {
/* triangle (upside down) */
u2 = u1*0.5;
u3 = u1*sqrt(0.75);
xm = [ u0, u3,-u3];
ym = [-u1, u2, u2];
} else if (symbol == 8) {
/* 5 branch star */
/* Notations: C18 = cos(18*ONE_DEGREE)
* S18 = sin(18*ONE_DEGREE)
* C54 = cos(54*ONE_DEGREE)
* S54 = sin(54*ONE_DEGREE)
*/
u2 = 0.224514*u1; // C54*S18/S54
u3 = 0.309017*u1; // S18
u4 = 0.951057*u1; // C18
u5 = 0.363271*u1; // C18*S18/S54
u6 = 0.118034*u1; // S18*S18/S54
u7 = 0.587785*u1; // C54
u8 = 0.809017*u1; // S54
u9 = 0.381966*u1; // S18/S54
xm = [ u0, u2, u4, u5, u7, u0,-u7,-u5,-u4,-u2];
ym = [ u1, u3, u3,-u6,-u8,-u9,-u8,-u6, u3, u3];
} else if (symbol > 0) {
/* N-side polygon in unit circle */
PI = 3.141592653589793238462643383279503;
a = (2.0*PI/symbol)*indgen(0:symbol-1);
xm = u1*cos(a);
ym = u1*sin(a);
} else {
error, "bad SYMBOL value";
}
__plp, y, x;
//fx=abs(limits()(1)-limits()(2))*0.05;
//fy=abs(limits()(3)-limits()(4))*0.05;
//limits,limits()(1)-fx,limits()(2)+fx,limits()(3)-fy,limits()(4)+fy;
}
func __plp(y, x)
/* DOCUMENT __plp, x, y;
Private routine used by plp. */
{
extern xm, ym, color, fill, legend, width;
local z;
n = array(1, 1 + numberof(y));
n(1) = numberof(ym);
if (fill && n(1) > 2) {
if (numberof(color) == 3) {
z = array(char, 3, numberof(n));
z(,) = color;
} else {
z = array(color, numberof(n));
}
}
plfp, z, grow(ym,y(*)), grow(xm,x(*)), n,
legend=legend, edges=1, ewidth=width, ecolor=color;
}
/*----------------------------------------------------------------------*/
func plpa(y, x, dx=, xlo=, xhi=, dy=, ylo=, yhi=, size=, symbol=, ticks=,
legend=, type=, width=, color=, fill=, every=, tosys=)
{
/* DOCUMENT plpa, y, x
or plpa, y
Plot with marker the buddle of curves Y versus X labelled by the
last indice.Y must be 2-dimensional, and X may be 2-dimensional,
1-dimensional
or omitted. If X is 2-dimensional, it must have the same dimensions
as Y and Y(,i) versus X(,i) is plotted for each last indice i. If
X is 1-dimensional, it must have the same length as the 1st dimension
of Y and Y(,i) versus X is plotted for each last indice i. If X is
omitted, it defaults to [1, 2, ..., numberof(Y(,1))].
The plotting keywords of plp are accepted. Most of then could be
array of the same lenght as the secund dimension of y
The optional keyword
every=N which can be used to plot every N curves in the bundle
(default N=1).
EXAMPLE
n = 10;
x = span(0,1,25);
y = x(,-)^indgen(1:n)(-,);
plpa, y, x,
every=1,
symbol=indgen(1:n),
color=-5-indgen(1:n),
legend=swrite(indgen(1:n));
*/
if(typeof(y) == "complex") y=[y.re,y.im];
if (is_void(every)) {
n= 1;
} else if (numberof(every)!=1 || (n= long(every(1))) <= 0) {
error, "EVERY must be a scalar >= 1";
}
if (dimsof(y)(1) == 1) {y = [y];}
y = y(,*);
imax= dimsof(y)(3);
if (is_void(x)) {
x2d= 0N;
} else {
x2d= dimsof(x)(1) >= 2;
}
// default for x
if(is_void(x)) x=indgen(1:numberof(y(, 1)));
// loop on i
for(i= (n+1)/2; i <= imax; i+= n) {
// test on x
px= x2d ? &x(,i) : &x;
// test on scalar keyword
ptype= numberof(type)(1)>=1 ? &type(i%numberof(type)) : &type;
pwidth= numberof(width)(1)>=1 ? &width(i%numberof(width)) : &width;
if (numberof(color) && dimsof(color)(1)==1)
pcolor= numberof(color)(1)>=1 ? &color(i%numberof(color)) : &color;
else if (!numberof(color)) pcolor=&[];
else
pcolor =numberof(color)(1,)>=1 ? &color(,i%numberof(color)) : &color;
plegend=numberof(legend)(1)>=1 ? &legend(i%numberof(legend)) : &legend;
psize= numberof(size)(1)>=1 ? &size(i%numberof(size)) : &size;
psymbol= numberof(symbol)(1)>=1 ? &symbol(i%numberof(symbol)) : &symbol;
pticks= numberof(ticks)(1)>=1 ? &ticks(i%numberof(ticks)) : &ticks;
pfill= numberof(fill)(1)>=1 ? &fill(i%numberof(fill)) : &fill;
ptosys= numberof(tosys) ? tosys(i%numberof(tosys)) : [] ;
// test on array keyword
pdx = (!is_void(dx) && dimsof(dx)(1)>=2) ? &dx(,i) : &dx;
pdy = (!is_void(dy) && dimsof(dy)(1)>=2) ? &dy(,i) : &dy;
pxlo= (!is_void(xlo) && dimsof(xlo)(1)>=2) ? &dxlo(,i) : &xlo;
pxhi= (!is_void(xhi) && dimsof(xhi)(1)>=2) ? &dxhi(,i) : &xhi;
pylo= (!is_void(ylo) && dimsof(ylo)(1)>=2) ? &dxlo(,i) : &ylo;
pyhi= (!is_void(yhi) && dimsof(yhi)(1)>=2) ? &dxhi(,i) : &yhi;
plsys, ptosys;
plp,y(, i), *px, dx=*pdx, xlo=*pxlo, xhi=*pxhi, dy=*pdy, ylo=*pylo,
yhi=*pyhi, size=*psize, symbol=*psymbol, ticks=*pticks,
legend=*plegend, type=*ptype, width=*pwidth, color=*pcolor,
fill=*pfill;
}
}
func plta(y, x, text, legend=, hide=, color=, font=, height=, opaque=,
orient=, justify=, tosys=)
{
/* DOCUMENT plta, y, x, text
or plta, y, text
*/
if (is_void(tosys)) tosys=1;
if(typeof(y) == "complex") y=[y.re,y.im];
if (is_void(every)) {
n= 1;
} else if (numberof(every)!=1 || (n= long(every(1))) <= 0) {
error, "EVERY must be a scalar >= 1";
}
if (is_void(y) && is_void(x) && !is_void(text) && tosys(1)==0) {
y=span(0.9,0.1, numberof(text(1,))) ;
x=span(0.1,0.7, numberof(text(,1))) ;
y=y(-:1:numberof(x),); x=x(,-:1:numberof(y));
}
if (is_void(y) && !is_void(text))
y=indgen(numberof(text(1,)))(-:1:numberof(text(,1)),);
else if (numberof(y)==1) y = y(-:1:numberof(x));
if (numberof(x)==1) x = x(-:1:numberof(y));
if (dimsof(y)(1) == 1) {y = [y];}
y = y(,*);
imax= dimsof(y)(3);
if (is_void(x)) {
x2d= 0N;
x=indgen(1:numberof(y(, 1)));
} else {
x2d= dimsof(x)(1) >= 2;
}
if (is_void(text)) {
text2d= 0N;
text=indgen(1:numberof(y(, 1)));
} else {
text2d= dimsof(text)(1) >= 2;
}
// default for x
// loop on i
for(i= (n+1)/2; i <= imax; i+= n) {
// test on x
px= x2d ? &x(,i) : &x;
ptext = text2d ? &text(,i) : &text;
// test on scalar keyword