-
Notifications
You must be signed in to change notification settings - Fork 2
/
plot.i
3279 lines (3090 loc) · 117 KB
/
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
/*
* plot.i --
*
* Additional routines for plotting in Yorick.
*
*-----------------------------------------------------------------------------
*
* Copyright (C) 1996, Eric Thiebaut <[email protected]>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*-----------------------------------------------------------------------------
*
* Routines:
* color_bar: add a color bar to a plot;
* pl3dj: plot disjoint lines in 3D space;
* pl3s: plot 3D surface;
* pl3t: plot text in 3D space;
* pl_box: draw a rectangle;
* pl_cbar: add a color bar to a plot;
* pl_cbox: draw a centered rectangle;
* pl_circle: draw a circle;
* pl_ellipse: draw an ellipse;
* pl_get_axis: parse axis settings;
* pl_get_color: parse color value/name;
* pl_get_font: parse font value/name;
* pl_get_symbol: parse symbol value/name;
* pl_img: plot an image with many options;
* pl_map: apply a function to all the elements of an array;
* pla: plot several curves at the same time;
* plh: plot in an "histogram" style;
* plhline: plot horizontal line across viewport;
* plp: plot points/error bars;
* pls: plot surface as a filled mesh with contours;
* plvline: plot vertical line across viewport;
* ps2png, ps2jpeg: convert PostScript file into bitmap image;
* win2png, win2jpeg: dump graphical window into bitmap image;
* win_copy_lim: copy plot limits between graphic windows;
* xbtn_plot: plot pseudo-GUI buttons;
* xbtn_which: manage pseudo-GUI buttons;
* xmouse: extended mouse interface;
* xmouse_box: interactively select and draw a rectangular region;
* xmouse_demo: simple demonstration of xmouse capabilities;
* xmouse_length: interactively measure a distance;
* xmouse_line: interactively select and draw a line;
* xmouse_point: interactively select and draw point(s);
* xwindow: setup viewport and graphic style of graphic windows;
*
* History:
* $Id: plot.i,v 1.3 2010-02-10 13:27:11 paumard Exp $
* $Log: plot.i,v $
* Revision 1.3 2010-02-10 13:27:11 paumard
* - Synchronize files with Eric Thiebaut's: fft_utils.i, img.i, plot.i, utils.i.
* - Import emulate_yeti.i
* - Remove basename() and dirname(), standard in pathfun.i.
* - Remove the accents in Erics name to prevent a crash on amd64.
*
* Revision 1.22 2008/09/04 07:19:30 eric
* - Some documentation fixes.
*
* Revision 1.21 2008/07/12 06:41:25 eric
* - Added c-basic-offset for Emacs.
*
* Revision 1.20 2008/07/11 20:43:17 eric
* - New routines: pl_img and pl_cbar.
*
* Revision 1.19 2007/07/25 17:02:19 eric
* - Some changes in pl_get_palette.
*
* Revision 1.18 2007/07/02 22:16:42 eric
* - Added "utils.i" as a required file.
*
* Revision 1.17 2007/07/02 22:15:18 eric
* - New routines: ps2png, ps2jpeg, win2png and win2jpeg.
*
* Revision 1.16 2007/05/31 07:14:09 eric
* - Fixed pl_get_color when argument is already a RGB triplet.
*
* Revision 1.15 2007/03/19 16:52:48 eric
* - Automatically include "style.i" is function `xwindow`.
*
* Revision 1.14 2007/02/06 12:05:18 eric
* Heavy changes in pl_get_color:
* a. allow for named colors from the X11 RGB database (more than 600
* color names);
* b. always return a color as a char array (either indexed color
* or [R,G,B] triplet); this should fix a bug which prevent to
* choose the inside color in plp;
* c. allow for multiple colors (array of colors);
* d. allow for packed RGB colors.
*
* Revision 1.13 2007/02/01 10:20:16 eric
* Quick reference for all routines added in top comment of this file.
*
* Revision 1.12 2007/02/01 10:09:22 eric
* There are a lot of changes this time:
*
* - 'plp' improved so that it is possible to draw 'transparent'
* symbols and to specify a different color for the inside and
* outline of the symbols;
*
* - new routines: 'pl_get_symbol', 'pl_get_color', 'pl_get_font',
* 'pl_get_axis' to parse and check values of standard graphic
* keywords;
*
* - new routine: 'xwindow' to manage graphic windows and setup
* viewport and graphic style;
*
* - new routines: 'xbtn_plot', 'xbtn_which' to create and manage
* GUI buttons in graphic windows;
*
* - new interactive routines: 'xmouse', 'xmouse_point', 'xmouse_box',
* 'xmouse_line', 'xmouse_length' and 'xmouse_demo';
*
* - new plotting routines to draw simple shapes: 'pl_box', 'pl_cbox',
* 'pl_circle', 'pl_ellipse';
*
* - new utility routine: 'pl_map' to apply a function to all the
* elements of an array.
*
* Revision 1.11 2007/01/16 08:15:01 eric
* - Fixed coding style and (some) documentation.
* - New functions plhline and plvline.
*
* Revision 1.2 2008/10/29 15:58:13 paumard
* utils.i: reform would not work with empty dimlist. Fixed.
* plot.i, util_fr.i, utils.i: rename functions now standard in Yorick (color_bar, rdfile, reform)
*
* Revision 1.1.1.1 2007/12/11 23:55:14 frigaut
* Initial Import - yorick-yutils
*
* 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
* - Mock check-in to synchronize version numbers because RCS
* master file was lost:
* - 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;
*
*-----------------------------------------------------------------------------
*/
require, "utils.i";
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 pl_img(img, clear=, cmin=, cmax=, zformat=, keeplimits=,
normalize=, pixelbias=, pixelsize=, pixelref=, pixelunits=)
/* DOCUMENT pl_img, img;
*
* Plot image IMG in current graphics window.
*
* Keyword CLEAR can be used to call fma command (which see): if CLEAR >
* 0, fma is called prior to drawing the image; if CLEAR < 0, fma is
* called after drawing the image (useful in animate mode); if CLEAR = 0
* or undefined, then fma is not called.
*
* Keyword ZFORMAT can be used to specify the format for the color bar
* labels (see pl_cbar).
*
* Keywords PIXELSIZE, PIXELBIAS and PIXELREF can be set to specify the
* pixel coordinates. The coordinate of the center of j-th pixel is
* given by:
*
* PIXELBIAS + PIXELSIZE*(j - PIXELREF)
*
* The default settings are PIXELBIAS=1.0, PIXELSCALE=1.0 and
* PIXELREF=1.0 (i.e. same coordinates as Yorick's indexing rules).
*
* Keyword PIXELUNITS can be used to specify the label(s) of the axis.
*
* PIXELSIZE, PIXELBIAS, PIXELREF and PIXELUNITS can have 1 or 2 elements
* to specify same or different settings for the X and Y axis.
*
* Keywords CMIN and CMAX can be used to specify cut levels for the
* display (see pli). If keyword NORMALIZE (see below) is true, CMIN and
* CMAX are in units of normalized intensity.
*
* If keyword NORMALIZE is true, the flux is normalized --- divided by
* the pixel area that is: PIXELSIZE(1)*PIXELSIZE(0).
*
*
* SEE ALSO:
* pli, fma, animate, pl_cbar, xytitles.
*/
{
dims = dimsof(img);
if (is_void(dims) || dims(1) != 2) {
error, "expecting a 2-D image";
}
width = dims(2);
height = dims(3);
if (is_void(pixelref)) {
pixelref = 1.0;
}
if (is_void(pixelbias)) {
pixelbias = 1.0;
}
if (is_void(pixelsize)) {
pixelsize = 1.0;
}
if (is_void(normalize)) {
scl = 1.0;
} else {
scl = 1.0/(pixelsize(1)*pixelsize(0));
if (scl != 1.0) {
img *= scl;
}
}
if (is_void(cmin)) cmin = min(img);
if (is_void(cmax)) cmax = max(img);
xsize = pixelsize(1);
ysize = pixelsize(0);
xbias = pixelbias(1);
ybias = pixelbias(0);
xref = pixelref(1);
yref = pixelref(0);
x0 = xbias + xsize*(0.5 - xref);
x1 = xbias + xsize*(width + 0.5 - xref);
y0 = ybias + ysize*(0.5 - yref);
y1 = ybias + ysize*(height + 0.5 - yref);
if (clear && clear > 0) {
fma;
}
pli, img, x0, y0, x1, y1, cmin=cmin, cmax=cmax;
local red, green, blue;
palette, red, green, blue, query=1;
ncolors = numberof(red);
levs = span(cmin, cmax, ncolors + 1);
colors = indgen(ncolors);
pl_cbar, cmin=cmin, cmax=cmax, vert=1, nlabs=11, format=zformat;
if (! is_void(pixelunits)) {
xytitles, pixelunits(1), pixelunits(0);
}
if (clear && clear < 0) {
fma;
}
}
func pl_cbar(z, cmin=, cmax=, vert=, nlabs=, adjust=,
color=, font=, height=, opaque=, orient=,
width=, ticklen=, thickness=, vport=, format=)
/* DOCUMENT pl_cbar, z;
* -or- pl_cbar, cmin=CMIN, cmax=CMAX;
*
* Draw a color bar below the current coordinate system the colors and
* the associated label values are from min(Z) to max(Z) -- alternatively
* keywords CMIN and CMAX can be specified. With the VERT=1 keyword the
* color bar appears to the left of the current coordinate system (vert=0
* is the default).
*
* Keyword NLABS can be used to choose the number of displayed labels; by
* default, NLABS=11 which correspond to a label every 10% of the
* dynamic; use NLABS=0 to suppress all labels. The format of the labels
* can be specified with keyword FORMAT; by default FORMAT= "%.3g". The
* font type, font height and text orientation for the labels can be set
* with keywords FONT (default "helvetica"), HEIGHT (default 14 points)
* and ORIENT respectively.
*
* By default the colorbar is drawn next to the current viewport; other
* viewport coordinates can be given by VPORT=[xmin,xmax,ymin,ymax].
* Keyword ADJUST can be used to move the bar closer to (adjust<0) or
* further from (adjust>0) the viewport.
*
* Keyword COLOR can be used to specify the color of the labels, the
* ticks and the frame of the colorbar. Default is foreground color.
*
* Keyword WIDTH can be used to set the width of the lines used to draw
* the frame and the ticks of the colorbar.
*
* Keyword TICKLEN can be used to set the lenght (in NDC units) of the
* ticks. Default is 0.007 NDC.
*
* Keyword THICKNESS can be used to set the thickness of the colorbar (in
* NDC units). Default is 0.020 NDC.
*
*
* SEE ALSO: pl_img, pli, plt, pldj, plg, viewport.
*/
{
if (is_void(cmin)) cmin = min(z);
if (is_void(cmax)) cmax = max(z);
if (is_void(vport)) vport = viewport();
if (is_void(adjust)) adjust = 0.0;
if (is_void(ticklen)) ticklen = 0.007;
if (is_void(thickness)) thickness = 0.020;
if (is_void(nlabs)) nlabs = 11;
local red, green, blue;
palette, red, green, blue, query=1;
ncolors = numberof(red);
if (ncolors < 2) {
ncolors = 240;
}
levs = span(cmin, cmax, ncolors + 1);
cells = char(indgen(0 : ncolors - 1));
linetype = 1; /* "solid" */
if (vert) {
x0 = vport(2) + adjust + 0.022;
x1 = x0 + thickness;
y0 = vport(3);
y1 = vport(4);
cells = cells(-,);
} else {
x0 = vport(1);
x1 = vport(2);
y0 = vport(3) - adjust - 0.045;
y1 = y0 - thickness;
cells = cells(,-);
}
sys = plsys(0);
pli, cells, x0, y0, x1, y1;
if (is_void(width) || width != 0) {
plg, [y0,y0,y1,y1], [x0,x1,x1,x0], closed=1,
color=color, width=width, type=linetype, marks=0;
}
if (nlabs) {
if (is_void(format)) format= "%.3g";
text = swrite(format=format, span(cmin, cmax, nlabs));
local lx0, lx1, lx2, ly0, ly1, ly2;
if (vert) {
lx0 = array(x1, nlabs);
lx1 = array(x1 + ticklen, nlabs);
lx2 = array(x1 + 1.67*ticklen, nlabs);
ly0 = span(y0, y1, nlabs);
eq_nocopy, ly1, ly0;
eq_nocopy, ly2, ly0;
justify = "LH";
} else {
ly0 = array(y1, nlabs);
ly1 = array(y1 - ticklen, nlabs);
ly2 = array(y1 - 1.67*ticklen, nlabs);
lx0 = span(x0, x1, nlabs);
eq_nocopy, lx1, lx0;
eq_nocopy, lx2, lx0;
justify = "CT";
}
if (ticklen && (is_void(width) || width != 0)) {
pldj, lx0, ly0, lx1, ly1,
color=color, width=width, type=linetype;
}
for (i = 1; i <= nlabs; ++i) {
plt, text(i), lx2(i), ly2(i), tosys=0, color=color, font=font,
height=height, opaque=opaque, orient=orient, justify=justify;
}
}
plsys, sys;
}
func __color_bar(levs, colors, vert=, labs=, adjust=, color=, width=,
height=, ticklen=, vport=, format=, font=)
/* DOCUMENT color_bar;
or color_bar, levs, colors;
Note: pl_cbar (which see) is probably a better routine.
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 n-th interface, LABS=[i,n]
forces a label every n-th interface starting at i-th interface
(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 (default "helvetica")
and the font height with keyword HEIGHT (default 14 points).
Keyword COLOR can be used to specify the color of the labels, the
ticks and the frame of the colorbar. Default is foreground color.
Keyword WIDTH can be used to set the width of the lines used to draw
the frame and the ticks of the colorbar.
Keyword TICKLEN can be used to set the lenght (in NDC units) of the
ticks. Default is 0.005 NDC.
SEE ALSO: pl_cbar, plfc. */
{
nil = string(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 {
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;
if (is_void(ticklen)) ticklen = 0.005;
dx = dy = 0.0;
if (vert) {
x = (vport(2)+adjust+[0.022,0.042])(-:1:n+1,);
dx = ticklen;
y = span(vport(3),vport(4),n+1)(,-:1:2);
} else {
y = (vport(3)-adjust-[0.045,0.065])(-:1:n+1,);
dy = -ticklen;
x = span(vport(1),vport(2),n+1)(,-:1:2);
}
sys = plsys(0);
plf,[colors],y,x,edges=1,ecolor=color,legend=nil;
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));
x= x(list,);
y= y(list,);
if (is_void(format)) format= "%g";
labs= swrite(format=format,levs(list));
plsys, 0;
pldj, x(,2),y(,2),x(,2)+dx,y(,2)+dy, legend=nil, color=color, width=width;
plsys, sys;
if (is_void(font)) font= "helvetica";
plt1, labs,x(,2)+2*dx,y(,2)+2*dy, justify=(vert?"LH":"CT"),
height=height, font=font, color=color;
}
}
if (!color_bar) color_bar=__color_bar;
/*---------------------------------------------------------------------------*/
func pla(y, x, every=, legend=, hide=, type=, width=, color=, closed=, smooth=,
marks=, marker=, mspace=, mphase=, rays=, arrowl=, arroww=, rspace=,
rphase=)
/* DOCUMENT pla, y, x
or pla, y
Plot the buddle of curves Y versus X labelled by their last dimension.
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 plus the optional keyword
EVERY=N which can be used to plot every N curves in the bundle
(default N=1).
EXAMPLE
x = span(0,1,25)(,-:1:25);
pla, x*transpose(x), marks=0, every=3;
SEE ALSO
plg, plp.
*/
{
if (is_void(every)) {
n = 1;
} else if (! is_array(every) || dimsof(every)(1) || (n = long(every)) <= 0) {
error, "EVERY must be a scalar >= 1";
}
if (! is_array(y) || dimsof(y)(1) != 2) {
error, "Y must be 2-dimensional";
}
imax = dimsof(y)(3);
if (is_void(x)) {
x2d = 0N;
} else {
x2d = dimsof(x)(1) >= 2;
}
for(i = (n+1)/2; i <= imax; i += n) {
px = (x2d ? &x(,i) : &x);
plg, y(, i), *px, legend=legend, hide=hide, type=type, width=width,
color=color, closed=closed, smooth=smooth, marks=marks, marker=marker,
mspace=mspace, mphase=mphase, rays=rays, arrowl=arrowl, arroww=arroww,
rspace=rspace, rphase=rphase;
}
}
/*---------------------------------------------------------------------------*/
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=)
/* 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.
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
*/
{
// 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;
x2= array(double, n2);
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 {
error, "bad value for JUST";
}
// build new Y vector
y2= array(double, n2);
y2(1::2)= y2(2::2)= y;
// plot the graph
plg, y2, x2,
legend=legend, hide=hide, type=type, width=width, color=color,
marks=marks, marker=marker, mspace=mspace, mphase=mphase;
}
/*---------------------------------------------------------------------------*/
func plhline(y, x0, x1, color=, width=, type=) {
lim = limits(); one = array(1.0, dimsof(y));
pldj, one*(is_void(x0) ? lim(1) : x0), y, one*(is_void(x1) ? lim(2) : x1), y,
color=color, width=width, type=type; }
func plvline(x, y0, y1, color=, width=, type=) {
lim = limits(); one = array(1.0, dimsof(x));
pldj, x, one*(is_void(y0) ? lim(3) : y0), x, one*(is_void(y1) ? lim(4) : y1),
color=color, width=width, type=type; }
/* DOCUMENT plhline, y;
-or- plhline, y, x0, x1;
-or- plvline, x;
-or- plhline, x, y0, y1;
Plots an horizontal/vertical line.
KEYWORDS color, type, width.
SEE ALSO pldj. */
/*---------------------------------------------------------------------------*/
/* PLP - PLOTTING POINTS */
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 (see
* pl_get_symbol).
*
* 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. The default is to draw open symbols. You can
* specify different colors for the outline and the inside of the symbol
* by using keyword COLOR = [EDGE_COLOR, FILL_COLOR].
*
* 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: LEGEND, TYPE, WIDTH,
* COLOR (TYPE is only used to draw error bars).
*
*
* EXAMPLES:
* plp, y, x, symbol='*', color=["orange","DarkSlateBlue"], fill=1,
* size=3, width=5;
*
*
* KEYWORDS:
* legend, type, width, color.
*
*
* SEE ALSO:
* pl_get_symbol, pl_get_color,
* 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.0100214; // radius of about 8 pixels at 75 DPI
if (! is_void(size)) u1 *= size;
/* parse color(s) */
if (is_array(color) && dimsof(color)(0) == 2) {
edge_color = pl_get_color(color(..,1));
if (fill) {
fill_color = pl_get_color(color(..,2));
}
} else {
edge_color = pl_get_color(color);
if (fill) {
fill_color = edge_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];
}