-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.sm
660 lines (621 loc) · 20.1 KB
/
plot.sm
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
__init_plot
load_colors
reset_plot
ptype 0 0
ctype default
ticksize 0 0 0 0
lt 0 lw 2
limits 0 1 0 1
expand 1
window 1 1 1 1
location 3500 31000 3500 31000
plot 2
# plot x y
limits $1 $2
ebox
connect $1 $2
xlabel $1
ylabel $2
pplot 23
# pplot x y
limits $1 $2
ebox
if ($?3) {
epoints $1 $2 $3
} else {
points $1 $2
}
xlabel $1
ylabel $2
logplot 2
local set lg$1=log($1)
local set lg$2=log($2)
plot lg$1 lg$2
errorplot 45
# errorplot x y xerr yerr
local set limx = min($1-$3) concat max($1+$3)
local set limy = min($2-$4) concat max($2+$4)
limits limx limy
ebox
if ($?5) {
epoints $1 $2 $5
} else {
points $1 $2
}
error_x $1 $2 $3
error_y $1 $2 $4
xlabel $1
ylabel $2
errorlogplot 4
# errorlog x y xerr yerr
local set x = log($1)
local set y = log($2)
local set x1 = log($1+$3)
local set x3 = log($1-$3)
local set y2 = log($2+$4)
local set y4 = log($2-$4)
local set limx = lmin(x3) concat max(x1)
local set limy = lmin(y4) concat max(y2)
local set e1=x1-x
local set e2=y2-y
local set e3=x-x3
local set e4=y-y4
limits limx limy
box
#con x y
errorbar x y e1 1
errorbar x y e2 2
errorbar x y e3 3
errorbar x y e4 4
xlabel log($1)
ylabel log($2)
ccon 25
# ccon x y [ctype=red lweight=2 ltype=0]
local define _ctype $ctype
local define _lweight $lweight
local define _ltype $ltype
local define color "red"
local define weight 2
local define type 0
if ($?3) {define color $3}
if ($?4) {define weight $4}
if ($?5) {define type $5}
ctype $color
lweight $weight
ltype $type
con $1 $2
ctype $_ctype
lweight $_lweight
ltype $_ltype
cshed 57
# cshed x y x2 y2 n [ctype=red angle=45]
local define _ctype $ctype
local define _angle $angle
local define color "red"
local define angl 45
if ($?6) {define color $6}
if ($?7) {define angl $7}
ctype $color
angle $angl
shed $1 $2 $3 $4 $5
ctype $_ctype
angle $_angle
ldraw 24
local define w 3
local define t 0
if ($?3) {define w $3}
if ($?4) {define t $4}
define _lw $lweight
define _lt $ltype
lw $w lt $t
draw $1 $2
lw $_lw lt $_lt
plot_pdf 35
if ($?5) {
pdf $1 $2 $3 $4 $5
} else {
if ($?4) {
pdf $1 $2 $3 $4
} else {
pdf $1 $2 $3
}
}
limits $2 $3
ebox
histogram $2 $3
xlabel $1
ylabel P($1)
ebox
ctype default
location 3500 31000 3500 31000
erase
box
fbox 03
local define ex 2
local define dx 0
local define dy 0
if ($?1) {define ex $1}
if ($?2) {define dx $2}
if ($?3) {define dy $3}
local define _ex $expand
local define _lw $lweight
expand $ex lw 3
ctype default
location $(3500+$dx) 31000 $(3500+$dy) 31000
erase
box
expand $_ex lw $_lw
wbox4 1
if ($1==1) {
window -2 -2 1 2
box 0 2 0 0
return
}
if ($1==2) {
window -2 -2 2 2
box 0 0 0 0
return
}
if ($1==3) {
window -2 -2 1 1
box 1 2 0 0
return
}
if ($1==4) {
window -2 -2 2 1
box 1 0 0 0
return
}
box
wbox6 1
if ($1==1) {
window -2 -3 1 3
box 0 2 0 0
return
}
if ($1==2) {
window -2 -3 2 3
box 0 0 0 0
return
}
if ($1==3) {
window -2 -3 1 2
box 0 2 0 0
return
}
if ($1==4) {
window -2 -3 2 2
box 0 0 0 0
return
}
if ($1==5) {
window -2 -3 1 1
box 1 2 0 0
return
}
if ($1==6) {
window -2 -3 2 1
box 1 0 0 0
return
}
window 1 1 1 1
box
wbox 2
local define bx 0
local define by 0
if (($1-1)%$2 == 0) {
define by 2
}
if (int(($1-1)/$2) == 0) {
define bx 1
}
box $bx $by 0 0
wbox_grid
define wx local
define wy local
do i=0,8 {
define wx ($i%3+1)
define wy (3-int($i/3))
window -3 -3 $wx $wy
wbox (3*($wy-1)+$wx) 3
}
rbox 12
# rbox 1|2 [rpos=0-32767]
ctype default
local define rpos 12000
if ($?2) {define rpos $2}
if ($1==0) {
location 3500 31000 3500 31000
}
if ($1==1) {
location 3500 31000 $rpos 31000
box 0 2 0 0
}
if ($1==2) {
location 3500 31000 3500 $rpos
box 1 2 0 0
}
ltick
# set log ticksize
ticksize -1 0 -1 0
vline 13
# draw vertical line at x=$1
local define ymin $fy1
local define ymax $fy2
if ($?2) {define ymax $2}
if ($?3) {define ymin $3}
relocate $1 $ymin
draw $1 $ymax
hline 13
# draw horizontal line at y=$1
local define xmin $fx1
local define xmax $fx2
if ($?2) {define xmax $2}
if ($?3) {define xmin $3}
relocate $xmin $1
draw $xmax $1
mline 2
# draw a line with m=$1, q=$2
relocate $fx1 $($1*$fx1+$2)
draw $fx2 $($1*$fx2+$2)
pline 2
# draw a line passing by two points
local define m (($2[1]-$2[0])/($1[1]-$1[0]))
local define q (($1[1]*$2[0]-$1[0]*$2[1])/($1[1]-$1[0]))
mline $m $q
shed45 45
local define prev_angle $angle
local define density 100
if ($?5) {define density $5}
angle 45
shed $1 $2 $3 $4 $density
angle $prev_angle
epoints 23
local define _old $expand
local define scale 2
if ($?3) {define scale $3}
expand $scale
points $1 $2
expand $_old
apoints 24
local define _ang $angle
angle 45
if ($?4) {angle $4}
if (!$?3) {
epoints $1 $2
} else {
epoints $1 $2 $3
}
angle $_ang
adot 01
local define _ang $angle
angle 45
if ($?1) {angle $1}
dot
angle $_ang
50shades 24
# 50shades color alpha [layer=white cname=MyShade]
# creates a new shade of $1 of ctype cname
# $2 controls the tinting/shading
# $3 is the color to layer, default is white
# $4 is the name of the new color, default is MyShade
local set clist = CTYPE()
local set cname = CTYPE(STRING)
local define cvalue (clist[sfind(cname,$1)])
local define R ($cvalue%256)
local define G (int($cvalue/256)%256)
local define B (int(int($cvalue/256)/256))
# tint/shade
# source: http://stackoverflow.com/questions/6615002/given-an-rgb-value-how-do-i-create-a-tint-or-shade
# The color resulting in layering a color RGB(currentR,currentG,currentB) with a color
# RGBA(aR,aG,aB,alpha) is:
# newR = currentR + (aR - currentR) * alpha
# newG = currentG + (aG - currentG) * alpha
# newB = currentB + (aB - currentB) * alpha
# where (aR,aG,aB) = black = (0,0,0) for shading, and (aR,aG,aB) = white = (255,255,255) for tinting
local define alpha $2
local define aR 255
local define aG 255
local define aB 255
if ($?3) {
define cvalue (clist[sfind(cname,$3)])
define aR ($cvalue%256)
define aG (int($cvalue/256)%256)
define aB (int(int($cvalue/256)/256))
}
if ($alpha<0) {
define alpha (-$alpha)
define aR (255-$aR)
define aG (255-$aG)
define aB (255-$aB)
}
define R (int($R + ($aR - $R)*$alpha))
define G (int($G + ($aG - $G)*$alpha))
define B (int($B + ($aB - $B)*$alpha))
local define cname "MyShade"
if ($?4) {define cname $4}
if ($DEBUG_ENABLED) {
echo "RGB:" $R $G $B
}
add_ctype $cname $R $G $B
color_box 57
# color_box x1 x2 y1 y2 alpha [color=red layer=white]
local define _lw $lweight
local define _ct $ctype
local define color "red"
local define layer "white"
if ($?6) {define color $6}
if ($?7) {define layer $7}
if ('$color'=='viridis') {
viridis (($5+1)*0.5)
ctype MyVir
} else {
50shades $color $5 $layer
ctype MyShade
}
lw 2
shade_box 0.1 $1 $3 $2 $4
lw $_lw ctype $_ct
test_color 12
local define alpha 0
if ($?2) {define alpha $2}
newdev
erase
color_box 0 1 0 1 $alpha $1
plot_color_x 46
# plot_color_x bin_centers alpha y1 y2 [color=red layer=white]
local set bb=binbounds($1)
local define color "red"
local define layer "white"
if ($?5) {define color $5}
if ($?6) {define layer $6}
define i local
do i=0,dimen($1)-1 {
color_box $(bb[$i]) $(bb[$i+1]) $3 $4 $($2[$i]) $color $layer
}
calib 01
local define color red
if ($?1) {define color $1}
device x11 -bg black -fg white -dev 0 -ndevice 10 -focus
color_box 0.00 1.00 0.00 1.00 -0.9 $color
color_box 0.05 0.95 0.05 0.95 -0.8 $color
color_box 0.10 0.90 0.10 0.90 -0.7 $color
color_box 0.15 0.85 0.15 0.85 -0.6 $color
color_box 0.20 0.80 0.20 0.80 -0.5 $color
color_box 0.25 0.75 0.25 0.75 -0.4 $color
color_box 0.30 0.70 0.30 0.70 -0.3 $color
color_box 0.35 0.65 0.35 0.65 -0.2 $color
color_box 0.40 0.60 0.40 0.60 -0.1 $color
color_box 0.45 0.55 0.45 0.55 -0. $color
device x11 -bg white -fg black -dev 1 -focus
color_box 0.00 1.00 0.00 1.00 0.9 $color
color_box 0.05 0.95 0.05 0.95 0.8 $color
color_box 0.10 0.90 0.10 0.90 0.7 $color
color_box 0.15 0.85 0.15 0.85 0.6 $color
color_box 0.20 0.80 0.20 0.80 0.5 $color
color_box 0.25 0.75 0.25 0.75 0.4 $color
color_box 0.30 0.70 0.30 0.70 0.3 $color
color_box 0.35 0.65 0.35 0.65 0.2 $color
color_box 0.40 0.60 0.40 0.60 0.1 $color
color_box 0.45 0.55 0.45 0.55 0. $color
50shadesof 12
local define layer "white"
if ($?2) {define layer $2}
local set x=0,1,0.02
local set y=-1,1,2/49
define x1 local
define x2 local
define alpha local
define i local
do i=0,dimen(y)-1 {
define x1 (x[$i])
define x2 (x[$i+1])
define alpha (y[$i])
color_box $x1 $x2 0 1 $alpha $1 $layer
}
color_scale 46
# color_scale x1 x2 y1 y2 color N
local define cscale "viridis"
if ($?5) {define cscale $5}
local define N 50
if ($?6) {define N $6}
local set y=$3,$4,($4-$3)/$N
local set a=-1,1,2/($N-1)
define y1 local define y2 local
define alpha local define i local
do i=0,dimen(a)-1 {
define y1 (y[$i])
define y2 (y[$i+1])
define alpha (a[$i])
color_box $1 $2 $y1 $y2 $alpha $cscale "white"
}
Nshadesof 13
local define N 50
if ($?2) {define N $2}
local define layer "white"
if ($?3) {define layer $3}
local set x=0,1,1/$N
local set y=-1,1,2/($N-1)
define x1 local
define x2 local
define alpha local
define i local
do i=0,dimen(y)-1 {
define x1 (x[$i])
define x2 (x[$i+1])
define alpha (y[$i])
color_box $x1 $x2 0 1 $alpha $1 $layer
}
grid_xy 56
# grid_xy xmin xmax ymin ymax xdim [ydim=xdim]
local define xmin $1
local define xmax $2
local define ymin $3
local define ymax $4
local define xdim $5
local define ydim $xdim
if ($?6) {define ydim $6}
local set xstep = $xmin,$xmax,($xmax-$xmin)/$xdim
local set ystep = $ymin,$ymax,($ymax-$ymin)/$ydim
define i local
do i=0,dimen(xstep)-1 {
vline $(xstep[$i]) $ymax $ymin
}
do i=0,dimen(ystep)-1 {
hline $(ystep[$i]) $xmax $xmin
}
newdev 01
# add a device (0-9)
local define d 0
if ($?1) {define d $1}
device x11 -dev $d -ndevice 10 -focus
ndev
# switch to next device
dev x11 -dev +
pdev
# switch to previous device
dev x11 -dev -
load_colors
# load the colors
add_ctype snow 255 250 250
add_ctype GhostWhite 248 248 255
add_ctype WhiteSmoke 245 245 245
add_ctype gainsboro 220 220 220
add_ctype mercury 230 230 230
add_ctype FloralWhite 255 250 240
add_ctype OldLace 253 245 230
add_ctype linen 250 240 230
add_ctype AntiqueWhite 250 235 215
add_ctype PapayaWhip 255 239 213
add_ctype BlanchedAlmond 255 235 205
add_ctype bisque 255 228 196
add_ctype PeachPuff 255 218 185
add_ctype NavajoWhite 255 222 173
add_ctype moccasin 255 228 181
add_ctype cornsilk 255 248 220
add_ctype ivory 255 255 240
add_ctype LemonChiffon 255 250 205
add_ctype seashell 255 245 238
add_ctype honeydew 240 255 240
add_ctype MintCream 245 255 250
add_ctype azure 240 255 255
add_ctype AliceBlue 240 248 255
add_ctype lavender 230 230 250
add_ctype LavenderBlush 255 240 245
add_ctype MistyRose 255 228 225
add_ctype white 255 255 255
add_ctype black 0 0 0
add_ctype DarkSlateGray 47 79 79
add_ctype DimGray 105 105 105
add_ctype SlateGray 112 128 144
add_ctype LightSlateGray 119 136 153
add_ctype gray 190 190 190
add_ctype LightGray 211 211 211
add_ctype MidnightBlue 25 25 112
add_ctype navy 0 0 128
add_ctype NavyBlue 0 0 128
add_ctype CornflowerBlue 100 149 237
add_ctype DarkSlateBlue 72 61 139
add_ctype SlateBlue 106 90 205
add_ctype MediumSlateBlue 123 104 238
add_ctype LightSlateBlue 132 112 255
add_ctype MediumBlue 0 0 205
add_ctype RoyalBlue 65 105 225
add_ctype blue 0 0 255
add_ctype DodgerBlue 30 144 255
add_ctype DeepSkyBlue 0 191 255
add_ctype SkyBlue 135 206 235
add_ctype LightSkyBlue 135 206 250
add_ctype SteelBlue 70 130 180
add_ctype LightSteelBlue 176 196 222
add_ctype LightBlue 173 216 230
add_ctype PowderBlue 176 224 230
add_ctype PaleTurquoise 175 238 238
add_ctype DarkTurquoise 0 206 209
add_ctype MediumTurquoise 72 209 204
add_ctype turquoise 64 224 208
add_ctype cyan 0 255 255
add_ctype LightCyan 224 255 255
add_ctype CadetBlue 95 158 160
add_ctype MediumAquamarine 102 205 170
add_ctype aquamarine 127 255 212
add_ctype DarkGreen 0 100 0
add_ctype DarkOliveGreen 85 107 47
add_ctype DarkSeaGreen 143 188 143
add_ctype SeaGreen 46 139 87
add_ctype MediumSeaGreen 60 179 113
add_ctype LightSeaGreen 32 178 170
add_ctype PaleGreen 152 251 152
add_ctype SpringGreen 0 255 127
add_ctype LawnGreen 124 252 0
add_ctype green 0 255 0
add_ctype chartreuse 127 255 0
add_ctype MediumSpringGreen 0 250 154
add_ctype GreenYellow 173 255 47
add_ctype LimeGreen 50 205 50
add_ctype YellowGreen 154 205 50
add_ctype ForestGreen 34 139 34
add_ctype OliveDrab 107 142 35
add_ctype DarkKhaki 189 183 107
add_ctype khaki 240 230 140
add_ctype PaleGoldenrod 238 232 170
add_ctype LightGoldenrodYellow 250 250 210
add_ctype LightYellow 255 255 224
add_ctype yellow 255 255 0
add_ctype gold 255 215 0
add_ctype LightGoldenrod 238 221 130
add_ctype goldenrod 218 165 32
add_ctype DarkGoldenrod 184 134 11
add_ctype RosyBrown 188 143 143
add_ctype IndianRed 205 92 92
add_ctype SaddleBrown 139 69 19
add_ctype sienna 160 82 45
add_ctype peru 205 133 63
add_ctype burlywood 222 184 135
add_ctype beige 245 245 220
add_ctype wheat 245 222 179
add_ctype SandyBrown 244 164 96
add_ctype tan 210 180 140
add_ctype chocolate 210 105 30
add_ctype firebrick 178 34 34
add_ctype brown 165 42 42
add_ctype DarkSalmon 233 150 122
add_ctype salmon 250 128 114
add_ctype LightSalmon 255 160 122
add_ctype orange 255 165 0
add_ctype DarkOrange 255 140 0
add_ctype coral 255 127 80
add_ctype LightCoral 240 128 128
add_ctype tomato 255 99 71
add_ctype OrangeRed 255 69 0
add_ctype red 255 0 0
add_ctype HotPink 255 105 180
add_ctype DeepPink 255 20 147
add_ctype pink 255 192 203
add_ctype LightPink 255 182 193
add_ctype PaleVioletRed 219 112 147
add_ctype maroon 176 48 96
add_ctype MediumVioletRed 199 21 133
add_ctype VioletRed 208 32 144
add_ctype magenta 255 0 255
add_ctype violet 238 130 238
add_ctype plum 221 160 221
add_ctype orchid 218 112 214
add_ctype grape 66 28 82
add_ctype LightGrape 140 117 181
add_ctype MediumOrchid 186 85 211
add_ctype DarkOrchid 153 50 204
add_ctype DarkViolet 148 0 211
add_ctype BlueViolet 138 43 226
add_ctype purple 160 32 240
add_ctype MediumPurple 147 112 219
add_ctype thistle 216 191 216
add_ctype DarkGrey 169 169 169
add_ctype DarkGray 169 169 169
add_ctype DarkBlue 0 0 139
add_ctype DarkCyan 0 139 139
add_ctype DarkMagenta 139 0 139
add_ctype DarkRed 139 0 0
add_ctype LightGreen 144 238 144
add_ctype antiRed 127 0 255
add_ctype indaco 75 0 130